Forum Moderators: phranque

Message Too Old, No Replies

basic htaccess index removal and cannonic form

         

bzgzd

3:17 pm on Feb 20, 2010 (gmt 0)

10+ Year Member



I have in my .htaccess file this (i copied it from some recommendations)
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*)index\.(s?html?|php[45]?)\ HTTP/
RewriteRule index\.(s?html?|php[45]?)$ http://www.example.com/%1 [R=301,L]

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

Now after I tried to understand it, I have two questions:
1. can I change rules to this?
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*)index\.(s?html?|php[45]?)\ HTTP/
RewriteRule .* http://www.example.com/%1 [R=301,L]

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

2. why that first rule can not be only like:
RewriteRule ^(.*)index\.(s?html?|php[45]?)$ http://www.example.com/$1 [R=301,L]

g1smd

4:15 pm on Feb 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Processing speed.

Beginning the pattern with (.*) means the parser has to back off and retry hundreds of matches before it finds the right one.

With
^[A-Z]{3,9}\ /(([^/]+/)*)index\.(s?html?|php[45]?)\ HTTP/
it can be parsed fom left to right in one cycle.

Also, if the external URL requests are being internally rewritten to index.php there would possibly be an infinite loop created. So, you need to check 'the request', literally the GET line sent by the browser.