Mobile app version of vmapp.org
Login or Join
Connie744

: 301 redirect to www from non-www and index.html Currently the home page of my website is accessible via these URL's: www.example.com, example.com, www.example.com/index.html, and example.com/index.html

@Connie744

Posted in: #301Redirect #NoWww

Currently the home page of my website is accessible via these URL's:
example.com, example.com, example.com/index.html, and example.com/index.html

So I'm trying to set up redirects so that example.com goes to example.com AND that example.com/index.html, example.com/index.html goes to example.com to avoid duplicate content issues. Tried this in the .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule .? www.example.com%{REQUEST_URI} [R=301,L]
Redirect 301 /index.html www.example.com/

But got error message that there were too many redirects. What do I need to include this .htaccess file to make this 301 redirect? I also have sub-domains like fr.example.com, de.example.com So do I also need to write separate 301 redirect rules/codes in their .htaccess file?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Connie744

1 Comments

Sorted by latest first Latest Oldest Best

 

@Angela700

Something such as the below will handle the canonical www redirect:-

RewriteEngine On
## canonical www 301 redirect
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ www.example.com/ [R=301,L]


The best rule to rewrite and 301 your various homepage URL's will vary depending on the website platform your website is built on though. Something along the lines of this may work though:-

## rewrite and 301 index pages
RewriteRule ^index.(php|html?)$ www.example.com/ [R=301,L]

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme