Forum Moderators: phranque
I've written some .htaccess code which is designed to redirect requests to just one file/script.
There are a few exemptions to this - e.g. I don't wan't the homepage or the about us page to be redirected.
The code below partially works - most things are redirected, while certain pages including the /contact-us/ avoid being redirected
However I'm having a major problem with the homepage: www.foobar.com/index.php doesn't get redirected (which is what I want) - but www.foobar.com/ does get redirected.
I tried adding in "||" and "|/|" to the last RewriteCond below to cover this - but when I do this nothing at all gets redirected. Is there a way around this?
RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.*
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !^.*.(jpg|jpeg|gif|js|css|class|png)$ [NC]
RewriteCond %{REQUEST_URI} !(/category/index.php|/index.php|/contact-us/index.php|/contact-us/) [NC]
RewriteRule ^.*$ /category/index.php
Fixing that, along with several errors (two serious), pattern-anchoring problems, and various redundancies and inefficiencies, yields:
Options +FollowSymlinks
RewriteEngine on
#
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
#
RewriteCond %{REQUEST_URI} !\.(jpe?g|gif|js|css|class|png)$ [NC]
RewriteCond %{REQUEST_URI} !^/(category/index\.php$|index\.php$|contact-us/) [NC]
RewriteRule ^.+$ /category/index.php [L]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]*/)*index\.php(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]*/)*)index\.php$ http://www.example.com/$1 [R=301,L]
Jim