Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 17th, 2005, 06:43 AM
Nel
Guest
 
Posts: n/a
Default .htaccess and PHP

Just looking for some general advice on modifying the URL for php.

I am using .htaccess to allow a web site to translate example.html to
index.php?content=example
(below)

ErrorDocument 404 http://www.example.com
RewriteEngine on
RewriteRule ^/?(.*).html$ /index.php?content=$1 [L]

Is there any downside to using this method. I just want to know before I
roll it out over several other sites.

Nel.


  #2  
Old July 17th, 2005, 06:43 AM
Justin Koivisto
Guest
 
Posts: n/a
Default Re: .htaccess and PHP

Nel wrote:[color=blue]
> Just looking for some general advice on modifying the URL for php.
>
> I am using .htaccess to allow a web site to translate example.html to
> index.php?content=example
> (below)
>
> ErrorDocument 404 http://www.example.com
> RewriteEngine on
> RewriteRule ^/?(.*).html$ /index.php?content=$1 [L]
>
> Is there any downside to using this method. I just want to know before I
> roll it out over several other sites.[/color]

This is a similar approach to what I've used on a handful of sites
(20-30). I haven't experienced any downside to this yet - unless there
is a problem on the server with the mod_rewrite or you are going to a
server other than Apache like zues or *gasp* IIS - in which case you'd
have to hope that ISAPI_rewrite and whatever Zues uses is compatible
enough to get you through.

--
Justin Koivisto - spam@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.
  #3  
Old July 17th, 2005, 06:43 AM
Edward Alfert
Guest
 
Posts: n/a
Default Re: .htaccess and PHP

"Nel" <nelly@ne14.co.NOSPAMuk> wrote in news:DwGxc.12894$NK4.1841718
@stones.force9.net:
[color=blue]
> Just looking for some general advice on modifying the URL for php.
>
> I am using .htaccess to allow a web site to translate example.html to
> index.php?content=example
> (below)
>
> ErrorDocument 404 http://www.example.com
> RewriteEngine on
> RewriteRule ^/?(.*).html$ /index.php?content=$1 [L]
>
> Is there any downside to using this method. I just want to know[/color]
before I[color=blue]
> roll it out over several other sites.
>
> Nel.
>[/color]

Nel,

I use something similar.
1) I redirect alias domains and domains without www. in front to my main
domain using a 301 redirect which is what Google likes in order to
maintain pagerank.
2) I test to make sure the page being requested is not a file or
directory that exists. If it exists, then retrive the existing page.
This is nice in case you want to have a pages that are not part of your
content management system.
3) I don't just redirect pages with .html extensions. I redirect
everything into content management system and then the cms parses the
requested page and strips extensions, trailing slashes, etc.



Options +SymlinksIfOwnerMatch

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.rootmode\.com
RewriteRule ^(.*)$ http://www\.rootmode\.com/$1 [R=
301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ $1 [L]

RewriteCond %{REQUEST_URI} !^/index\.php
RewriteRule ^(.*)$ /index.php?page=$1 [L]


--
Edward Alfert
http://www.rootmode.com/
Multiple Domain Hosting and Reseller Hosting Plans
Coupon Code (Recurring $5/month Discount): newsgroup

  #4  
Old July 17th, 2005, 06:44 AM
Chung Leong
Guest
 
Posts: n/a
Default Re: .htaccess and PHP

"Nel" <nelly@ne14.co.NOSPAMuk> wrote in message
news:DwGxc.12894$NK4.1841718@stones.force9.net...[color=blue]
> Just looking for some general advice on modifying the URL for php.
>
> I am using .htaccess to allow a web site to translate example.html to
> index.php?content=example
> (below)
>
> ErrorDocument 404 http://www.example.com
> RewriteEngine on
> RewriteRule ^/?(.*).html$ /index.php?content=$1 [L]
>
> Is there any downside to using this method. I just want to know before I
> roll it out over several other sites.[/color]

Other then losing the ability to use regular .html files, there's no major
downside I can think of. Then again, there's little upside to doing things
this way. If you don't need to use Apache rewrite, my advise is to not use
it.


  #5  
Old July 17th, 2005, 06:44 AM
Nel
Guest
 
Posts: n/a
Default Re: .htaccess and PHP

"Edward Alfert" <ealfert@rootmode.com> wrote in message
news:Xns9503CBB689139ealfertrootmodecom@130.133.1. 4...[color=blue]
> "Nel" <nelly@ne14.co.NOSPAMuk> wrote in news:DwGxc.12894$NK4.1841718
> @stones.force9.net:
>[color=green]
> > Just looking for some general advice on modifying the URL for php.
> >
> > I am using .htaccess to allow a web site to translate example.html to
> > index.php?content=example
> > (below)
> >
> > ErrorDocument 404 http://www.example.com
> > RewriteEngine on
> > RewriteRule ^/?(.*).html$ /index.php?content=$1 [L]
> >
> > Is there any downside to using this method. I just want to know[/color]
> before I[color=green]
> > roll it out over several other sites.
> >
> > Nel.
> >[/color]
>
> Nel,
>
> I use something similar.
> 1) I redirect alias domains and domains without www. in front to my main
> domain using a 301 redirect which is what Google likes in order to
> maintain pagerank.
> 2) I test to make sure the page being requested is not a file or
> directory that exists. If it exists, then retrive the existing page.
> This is nice in case you want to have a pages that are not part of your
> content management system.
> 3) I don't just redirect pages with .html extensions. I redirect
> everything into content management system and then the cms parses the
> requested page and strips extensions, trailing slashes, etc.
>
>
>
> Options +SymlinksIfOwnerMatch
>
> RewriteEngine On
>
> RewriteCond %{HTTP_HOST} !^www\.rootmode\.com
> RewriteRule ^(.*)$ http://www\.rootmode\.com/$1 [R=
> 301,L]
>
> RewriteCond %{REQUEST_FILENAME} -f [OR]
> RewriteCond %{REQUEST_FILENAME} -d
> RewriteRule ^(.*)$ $1 [L]
>
> RewriteCond %{REQUEST_URI} !^/index\.php
> RewriteRule ^(.*)$ /index.php?page=$1 [L]
>
>
> --
> Edward Alfert
> http://www.rootmode.com/
> Multiple Domain Hosting and Reseller Hosting Plans
> Coupon Code (Recurring $5/month Discount): newsgroup[/color]

One of the reasons I am using .html is to give the site the look and feel of
a static html web site. I was under the impression, that with some
exceptions (like Google) search engines list the pages better than
index.php?content=example.
[color=blue]
> 2) I test to make sure the page being requested is not a file or
> directory that exists. If it exists, then retrive the existing page.
> This is nice in case you want to have a pages that are not part of your
> content management system.[/color]
If I need a stand alone page, it will probably have some php requirement, so
I would probably just call existing pages example.php. I'm not likely to
ever have static html files that could not be moved over to content
management.

Thanks for the detailed feedback. I had a look at your web site and see
what you mean. It works very well! :-)

Nel.


  #6  
Old July 17th, 2005, 06:44 AM
Nel
Guest
 
Posts: n/a
Default Re: .htaccess and PHP

"Chung Leong" <chernyshevsky@hotmail.com> wrote in message
news:SK-dnc0eOqwUcVrd4p2dnA@comcast.com...[color=blue]
> "Nel" <nelly@ne14.co.NOSPAMuk> wrote in message
> news:DwGxc.12894$NK4.1841718@stones.force9.net...[color=green]
> > Just looking for some general advice on modifying the URL for php.
> >
> > I am using .htaccess to allow a web site to translate example.html to
> > index.php?content=example
> > (below)
> >
> > ErrorDocument 404 http://www.example.com
> > RewriteEngine on
> > RewriteRule ^/?(.*).html$ /index.php?content=$1 [L]
> >
> > Is there any downside to using this method. I just want to know before[/color][/color]
I[color=blue][color=green]
> > roll it out over several other sites.[/color]
>
> Other then losing the ability to use regular .html files, there's no major
> downside I can think of. Then again, there's little upside to doing things
> this way. If you don't need to use Apache rewrite, my advise is to not use
> it.
>[/color]
As I just posted above Chung, I was under the impression that example.html
was easier for search engines to map.

Nel


  #7  
Old July 17th, 2005, 06:44 AM
Edward Alfert
Guest
 
Posts: n/a
Default Re: .htaccess and PHP

"Nel" <nelly@ne14.co.NOSPAMuk> wrote in
news:LvUxc.13163$NK4.1896572@stones.force9.net:
[color=blue]
> "Edward Alfert" <ealfert@rootmode.com> wrote in message
> news:Xns9503CBB689139ealfertrootmodecom@130.133.1. 4...[color=green]
>> "Nel" <nelly@ne14.co.NOSPAMuk> wrote in news:DwGxc.12894$NK4.1841718
>> @stones.force9.net:
>>[color=darkred]
>> > Just looking for some general advice on modifying the URL for php.
>> >
>> > I am using .htaccess to allow a web site to translate example.html
>> > to index.php?content=example
>> > (below)
>> >
>> > ErrorDocument 404 http://www.example.com
>> > RewriteEngine on
>> > RewriteRule ^/?(.*).html$ /index.php?content=$1 [L]
>> >
>> > Is there any downside to using this method. I just want to know[/color]
>> before I[color=darkred]
>> > roll it out over several other sites.
>> >
>> > Nel.
>> >[/color]
>>
>> Nel,
>>
>> I use something similar.
>> 1) I redirect alias domains and domains without www. in front to my
>> main domain using a 301 redirect which is what Google likes in order
>> to maintain pagerank.
>> 2) I test to make sure the page being requested is not a file or
>> directory that exists. If it exists, then retrive the existing page.
>> This is nice in case you want to have a pages that are not part of
>> your content management system.
>> 3) I don't just redirect pages with .html extensions. I redirect
>> everything into content management system and then the cms parses the
>> requested page and strips extensions, trailing slashes, etc.
>>
>>
>>
>> Options +SymlinksIfOwnerMatch
>>
>> RewriteEngine On
>>
>> RewriteCond %{HTTP_HOST} !^www\.rootmode\.com
>> RewriteRule ^(.*)$ http://www\.rootmode\.com/$1 [R=
>> 301,L]
>>
>> RewriteCond %{REQUEST_FILENAME} -f [OR]
>> RewriteCond %{REQUEST_FILENAME} -d
>> RewriteRule ^(.*)$ $1 [L]
>>
>> RewriteCond %{REQUEST_URI} !^/index\.php
>> RewriteRule ^(.*)$ /index.php?page=$1 [L]
>>
>>
>> --
>> Edward Alfert
>> http://www.rootmode.com/
>> Multiple Domain Hosting and Reseller Hosting Plans
>> Coupon Code (Recurring $5/month Discount): newsgroup[/color]
>
> One of the reasons I am using .html is to give the site the look and
> feel of a static html web site. I was under the impression, that with
> some exceptions (like Google) search engines list the pages better
> than index.php?content=example.
>[color=green]
> > 2) I test to make sure the page being requested is not a file or
>> directory that exists. If it exists, then retrive the existing page.
>> This is nice in case you want to have a pages that are not part of
>> your content management system.[/color]
> If I need a stand alone page, it will probably have some php
> requirement, so I would probably just call existing pages example.php.
> I'm not likely to ever have static html files that could not be moved
> over to content management.
>
> Thanks for the detailed feedback. I had a look at your web site and
> see what you mean. It works very well! :-)
>
> Nel.
>[/color]

Nel,

The url is not rewritten to http://www.domain.tld/index.php?
content=example... it stays http://www.domain.tld/example so search
engines do not see that it is a dynamic site. They see a static url.

The site you looked at uses a differnt but similar technique that has
some drawbacks (like not being able to handle trailing slashes "/").
The code I listed is for the redesign I'm currently working on.

The code above is only the .htaccess portion, see the index.php page
that does other manipulation (not 100% done yet).

<?php
//========================================
//RootMode CMS - http://cms.rootmode.com/
//----------------------------------------

/*****************************************
Place the following in .htaccess in root directory
Make sure to modify domain in first RewriteCond and RewriteRule
******************************************
Options +SymlinksIfOwnerMatch

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.rootmode\.net
RewriteRule ^(.*)$ http://www\.rootmode\.net/$1 [R=
301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ $1 [L]

RewriteCond %{REQUEST_URI} !^/index\.php
RewriteRule ^(.*)$ /index.php?page=$1 [L]
*****************************************/

//========================================
//Set system/site specific variables
//----------------------------------------
$domain = $_SERVER["HTTP_HOST"]; //Can also set
manually to "www.domain.tld"
$path = "/var/www/html/"; //Absolute path is
preferred but relative will work
$dir_content = "content/";
$ext = ".php"; //Extension of
physical content files. Will not be displayed in address bar of
browser.
$page_default = "multiple-domain-hosting"; //No extension
$redirect_default = true; //true or false.
Useful for search engine optimization if set to true along with a
descriptive $page_default.
$page_404 = "sitemap"; //No extension
$dir_template = "template/";
$page_header = "header.php"; //Extension
required
$page_footer = "footer.php"; //Extension
required
$debug = true; //true or false

//========================================
//DO NOT MODIFY BELOW THIS LINE
//----------------------------------------

//========================================
//Send email if referred is a search engine
//----------------------------------------

//========================================
//Read requested page from mod_rewrite rule in .htaccess
//----------------------------------------
$page_content = $_REQUEST["page"];
if ($debug) { echo "(Test=User Requested Page):
page_content=".$page_content."<br />"; };

//========================================
//If no page was specified, retrieve default page
//----------------------------------------
if ((!$page_content) && ($redirect_default)) {
$page_redirect = $page_default;};
if ($debug) { echo "(Test=Redirect Default):
page_redirect=".$page_redirect."<br />"; };
if (!$page_content) { $page_content = $page_default; };
if ($debug) { echo "(Test=Default Page):
page_content=".$page_content."<br />"; };

//========================================
//If exists, remove trailing "/"
//Fix for search engines that append a "/" if the file being
requested does not have an extension
//Do not redirect to non-slash version because it might create a
loop
//----------------------------------------
if (substr($page_content,-1,1) == "/") { $page_content =
substr($page_content,0,-1); };
if ($debug) { echo "(Test=Trailing Slash):
page_content=".$page_content."<br />"; };

//========================================
//If exists, remove "." or ">"
//Fix for common problems of mangled links in emails
//----------------------------------------
$lastchar = substr($page_content, -1, 1);
if (($lastchar == '.') || ($lastchar == '>')) {
$page_redirect = substr($page_content, 0, -1); $page_content =
$page_redirect; };
if ($debug) { echo "(Test=Trailing . or >):
page_redirect=".$page_redirect."<br />"; };

//========================================
//If exists, remove extension
//----------------------------------------
//.htm, .php
if (substr($page_content,-4,1) == ".") {
$page_redirect = substr($page_content,0,-4); $page_content =
$page_redirect; };
//.html, .php3
if (substr($page_content,-5,1) == ".") {
$page_redirect = substr($page_content,0,-5); $page_content =
$page_redirect; };
//.shtml
if (substr($page_content,-6,1) == ".") {
$page_redirect = substr($page_content,0,-6); $page_content =
$page_redirect; };
if ($debug) { echo "(Test=Strip Extension): page_redirect=".
$page_redirect."<br />"; };

//========================================
//Force lower case for filename
//----------------------------------------
$page_content_lower = strtolower($page_content);
if ($page_content != $page_content_lower) { $page_redirect =
$page_content_lower; $page_content = $page_redirect; };
if ($debug) { echo "(Test=Lower Case):
page_redirect=".$page_redirect."<br />"; };

//========================================
//If requested page does not exist, then redirect to 404 page
//----------------------------------------
$file = $path.$dir_content.$page_content.$ext;
if ($debug) { echo "(Test=Physical Path): file=".
$file."<br />"; };
if (!file_exists($file)) { $page_redirect = $page_404; };
if ($debug) { echo "(Test=404): page_redirect=".
$page_redirect."<br />"; };

//========================================
//Determine which template (header and footer) to use
//----------------------------------------
if (!file_exists($path.$dir_content.$page_header)) {
$dir_header = $dir_content; } else { $dir_header = $dir_template; };
if ($debug) { echo "(Test=Header Path): dir_header=".
$dir_header."<br />"; };
if (!file_exists($path.$dir_content.$page_footer)) {
$dir_footer = $dir_content; } else { $dir_footer = $dir_template; };
if ($debug) { echo "(Test=Footer Path): dir_footer=".
$dir_footer."<br />"; };

//========================================
//Display content or do a 301 redirect to correct page
//----------------------------------------
if (!$page_redirect) {
include($path.$dir_header.$page_header);
include($path.$dir_content.$page_content.$ext);
include($path.$dir_footer.$page_footer);
} else {
header("Location: http://$domain/$page_redirect");
header("HTTP/1.0 301 Moved Permanently", true);
}

//========================================
//Helpful troubleshooting info
//----------------------------------------
if ($debug) { echo phpinfo(); };
//Uncomment next line to display phpinfo() even when not in
debug mode
//echo phpinfo();
?>

--
Edward Alfert
http://www.rootmode.com/
Multiple Domain Hosting and Reseller Hosting Plans
Coupon Code (Recurring $5/month Discount): newsgroup

  #8  
Old July 17th, 2005, 06:45 AM
Virgil Green
Guest
 
Posts: n/a
Default Re: .htaccess and PHP

"Nel" <nelly@ne14.co.NOSPAMuk> wrote in message
news:LvUxc.13163$NK4.1896572@stones.force9.net...[color=blue]
> "Edward Alfert" <ealfert@rootmode.com> wrote in message
> news:Xns9503CBB689139ealfertrootmodecom@130.133.1. 4...[color=green]
> > "Nel" <nelly@ne14.co.NOSPAMuk> wrote in news:DwGxc.12894$NK4.1841718
> > @stones.force9.net:
> >[color=darkred]
> > > Just looking for some general advice on modifying the URL for php.
> > >
> > > I am using .htaccess to allow a web site to translate example.html to
> > > index.php?content=example
> > > (below)
> > >
> > > ErrorDocument 404 http://www.example.com
> > > RewriteEngine on
> > > RewriteRule ^/?(.*).html$ /index.php?content=$1 [L]
> > >
> > > Is there any downside to using this method. I just want to know[/color]
> > before I[color=darkred]
> > > roll it out over several other sites.
> > >
> > > Nel.
> > >[/color]
> >
> > Nel,
> >
> > I use something similar.
> > 1) I redirect alias domains and domains without www. in front to my main
> > domain using a 301 redirect which is what Google likes in order to
> > maintain pagerank.
> > 2) I test to make sure the page being requested is not a file or
> > directory that exists. If it exists, then retrive the existing page.
> > This is nice in case you want to have a pages that are not part of your
> > content management system.
> > 3) I don't just redirect pages with .html extensions. I redirect
> > everything into content management system and then the cms parses the
> > requested page and strips extensions, trailing slashes, etc.
> >
> >
> >
> > Options +SymlinksIfOwnerMatch
> >
> > RewriteEngine On
> >
> > RewriteCond %{HTTP_HOST} !^www\.rootmode\.com
> > RewriteRule ^(.*)$ http://www\.rootmode\.com/$1 [R=
> > 301,L]
> >
> > RewriteCond %{REQUEST_FILENAME} -f [OR]
> > RewriteCond %{REQUEST_FILENAME} -d
> > RewriteRule ^(.*)$ $1 [L]
> >
> > RewriteCond %{REQUEST_URI} !^/index\.php
> > RewriteRule ^(.*)$ /index.php?page=$1 [L]
> >
> >
> > --
> > Edward Alfert
> > http://www.rootmode.com/
> > Multiple Domain Hosting and Reseller Hosting Plans
> > Coupon Code (Recurring $5/month Discount): newsgroup[/color]
>
> One of the reasons I am using .html is to give the site the look and feel[/color]
of[color=blue]
> a static html web site. I was under the impression, that with some
> exceptions (like Google) search engines list the pages better than
> index.php?content=example.
>[/color]

If you'd like to see a rather extensive use of rewrite to convert dynamic
URLs to apparently static URLs, you might want to visit www.nukecops.com and
take a look at the GoogleTap proposal that is fairly popular with phpNuke
users. I've looked at for educational purposes but have not chosen to use
it. It handles the re-write on incoming transactiosn and also rewrites
outbound html.

- Virgil


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles