Solved

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

Posted on 2016-08-08
4
110 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 8

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
 
LVL 1

Author Closing Comment

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

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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

856 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