Link to home
Start Free TrialLog in
Avatar of boltweb
boltwebFlag for Spain

asked on

.htaccess rewrite rule to 301 redirect canonical versions of homepage to root

We have an apache webserver and neet to modify the .htaccess file so that all possible canonical versions of our homepage redirect to the root of domain without the trailing slash i.e. we want the homepage to have this URL:   http://www.our-website.com   

We setup some .htaccess redirects which deal most of the canonicals however when we found that we also need to redirect http://www.our-website.com/index.html  TO root  http://www.our-site.com  

 What would be the additional rewrite rule we need to add to the ones we have already  to do this?

This is what we have so far in our .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^our-website.com
RewriteRule (.*) http://www.our-website.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^[0-9]+(\.[0-9]+){3} [OR]
RewriteCond %{HTTP_HOST} ^our-website\.com
RewriteRule (.*) http://www.our-website.com/$1 [R=301,L]
rewritecond %{HTTP_HOST} ^our-website\.com
rewriteRule ^(.*) http://www.our-website.com/$1 [R=301,L]


Thank you
ASKER CERTIFIED SOLUTION
Avatar of James Bilous
James Bilous
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
try below code :

RewriteEngine On
RewriteBase /

# redirect html pages to the root domain
RewriteRule ^index\.html$ / [NC,R,L]
Avatar of boltweb

ASKER

Thank you. It worked perfectly.
Avatar of boltweb

ASKER

Thank you for your reply. I had already implemented the first solution so I do not yet know if your solution would have worked.  I just wanted to say thank you anyway.