htaccess: how to redirect index.html to www?
Options +FollowSymlinks RewriteEngine on #redirect non www to www RewriteCond %{HTTP_HOST} ^domain.com$ [NC] RewriteRule ^(.*)$ http://www.domain.com/$1 [r=301,NC] #redirect index.html to domain name RewriteRule ^index.html$ / [R=301,L] RewriteRule ^(.*)/index.html$ /$1/ [R=301,L] #add trailing slash to all pages RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [L,R=301]
Non www to www
The first part successfully redirects from domain.com to www.domain.com/.
index.html to www.domain.com
The second part only redirects www.domain.com/index.html to www.domain.com/
If I test with domain.com/index.html (no www) then it fails and redirects to http://domain.com/http://www.domain.com/ throwing up a 404.
Trailing Slash
Adding a trailing slash successfully changes domain.com to www.domain.com/ - but www.domain.com stays the same.
Anyone know where the errors are in the code?
-
beelzebomb -
Thanks
{{ DiscussionBoard.errors[9565143].message }} -