Htaccess to 301 redirect index.html and www

Trying to set up redirects so that http://mysite.com goes to http://www.mysite.com/ AND that http://www.mysite.com/index.html goes to http://www.mysite.com/

Tried this in the htaccess file

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\\.mysite\\.com$ [NC]
RewriteRule .? http://www.mysite.com%{REQUEST_URI} [R=301,L]

Redirect 301 /index.html http://www.mysite.com/

But got error msg that there were too many redirects.

Any suggestions?

Instead of the Redirect 301, try this


RewriteRule ^index\\.html$ http://www.mysite.com/ [L,R=301]

Technically, when you request / you request index.html (given index.html is the DirectoryIndex, which is usually the case) so that will indeed result in a loop. If I’m not mistaken RewriteRules checks against the requested URL, not against the requested file, so the problem shouldn’t exist there. If it does, there are other ways we can use, but try this one first :slight_smile:

Worked perfectly. Thanks!