I have a domain like example.test.com. The website consists of three different html files:
- index.html
- products.html
- contact.html
So if a user types in example.test.com/index.html the url should be redirected to example.test.com.
Also example.test.com/index should become example.test.com
example.test.com/contact.html should be example.test.com/contact and so on.
Their should be no www before the url.
I came up with the following rules:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^example.test.com$ [NC]
RewriteRule ^(.*)$ http://example.test.com/$1 [L,R=301]
RewriteCond %{SCRIPT_FILENAME}/ -d
RewriteCond %{SCRIPT_FILENAME}.html !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.+)\.html$ /$1 [R=301,L]
RewriteCond %{SCRIPT_FILENAME}.html -f
RewriteRule [^/]$ %{REQUEST_URI}.html [QSA,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(html?|php)\ HTTP/
RewriteRule ^index\.(html?|php)$ http://example.test.com/ [R=301,L]
In Firefox everything works as expected, but in Chrome and Internet Explorer example.test.com/index.html is only redirected to example.test.com/index and I don’t know why.
I’m not really sure what you are trying to achieve with the
^[A-Z]{3,9}\part but the culprit here is the dot at the end of index in your last condition. Change it to :and this should work fine.