Forum Moderators: phranque
RewriteOptions inherit
RewriteEngine On
RewriteCond %{THE_REQUEST} ^.*/index.htm
RewriteRule ^(.*)index.htm$ http://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} \.php
RewriteRule ^tips/([^.]+)\.php$ http://www.example.com/example/$1/ [R=301,L]
RewriteRule ^tips/([^.]+[^./])$ http://www.example.com/example/$1/ [R=301,L]
RewriteRule ^(tips/[^.]+)/$ /$1.php [L]
RewriteCond %{HTTP_HOST} ^example\.com [NC]
# redirect non-www tips to www + correct
RewriteRule ^tips/([^.]+)\.php$ http://www.example.com/example/$1/ [R=301,L]
# rewrite all other non-www to www
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
# carry on with the_request rules
RewriteOptions inherit
RewriteEngine On
RewriteCond %{THE_REQUEST} ^.*/index.htm
RewriteRule ^(.*)index.htm$ http://www.example.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} \.php
RewriteRule ^tips/([^.]+)\.php$ http://www.example.com/example/$1/ [R=301,L]
RewriteRule ^tips/([^.]+[^./])$ http://www.example.com/example/$1/ [R=301,L]
RewriteRule ^(tips/[^.]+)/$ /$1.php [L]
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.www.example.com/$1 [R=301,L]
and then the most specific rules precede the most general rules
RewriteEngine On
RewriteCond %{THE_REQUEST} \.php
RewriteRule ^tips/([^.]+)\.php$ http://www.example.com/tips/$1/ [R=301,L]
RewriteRule ^tips/([^.]+[^./])$ http://www.example.com/tips/$1/ [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/index.htm
RewriteRule ^(.*)index.htm$ http://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^(tips/[^.]+)/$ /$1.php [L]
I do not understand re-write rules / htaccess at all - it may as well be in Chinese
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
you can think of it as four cells in a table. (This is assuming you know at least a tiny bit of html.) And then you think of the whole "table" as having a header: RewriteCond %{THE_REQUEST} \.php
RewriteRule ^tips/([^.]+)\.php$ http://www.example.com/tips/$1/ [R=301,L]
RewriteRule ^tips/([^.]+)\.php$ http://www.example.com/tips/$1/ [R=301,L] RewriteCond %{THE_REQUEST} ^.*/index.htm
RewriteRule ^(.*)index.htm$ http://www.example.com/$1 [R=301,L]
RewriteRule ^(.*)index\.htm$ http://www.example.com/$1 [R=301,L] RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$ [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
If I change those first two lines at all, it messes everything up.
In relation to the index.htm redirect to / ... Could I just ask why these rules are better than what I already had?
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$ [NC]
this says if the url path ends with .php make sure THE_REQUEST also contains .php before redirecting the request.
try this instead:
RewriteRule ^(.*)index\.htm$ http://www.example.com/$1 [R=301,L]