Solved

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

Posted on 2016-08-08
4
63 Views
Last Modified: 2016-08-08
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
0
Comment
Question by:boltweb
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
James Bilous earned 500 total points
ID: 41747397
Perhaps something like the following:

RewriteEngine On
RewriteRule ^index\.html$ / [R=301,L]

Open in new window

0
 
LVL 7

Expert Comment

by:Swatantra Bhargava
ID: 41747455
try below code :

RewriteEngine On
RewriteBase /

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

Author Closing Comment

by:boltweb
ID: 41747503
Thank you. It worked perfectly.
0
 

Author Comment

by:boltweb
ID: 41747507
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.
0

Featured Post

Superior storage. Superior surveillance.

WD Purple drives are built for 24/7, always-on, high-definition security systems. With support for up to 8 hard drives and 32 cameras, WD Purple drives are optimized for surveillance.

Join & Write a Comment

A few customers have recently asked my thoughts on Password Managers.  As Security is a big part of our industry I was initially very hesitant and sceptical about giving a program all of my secret passwords.  But as I was getting asked about them mo…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now