1

I was analyzing my webpage SEO using an online tool where I saw that my HTTP status for my root domain name www.example.com was resulting in a 301 redirect to www.example.com/index.html.

I would much rather have my root domain returning a 200 result instead- but I set up my 301 redirects a long time ago and now I am not sure how to alter my code to resolve this. I have noticed my website's main root domain disappearing from the SERPs (being replaced, in most cases, with a sub domain page) and I am afraid that this 301 redirect may be affecting my root domain's ability to rank.

My .htaccess file begins with this code:

Options +FollowSymLinks 
RewriteEngine on 
RewriteCond %{HTTP_HOST} ^example.com [NC] 
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

Followed by my individual redirects.

My index.html page includes the code:

<link rel="canonical" href="http://www.example.com">  

And I have Google webmaster tools set up to have any instances of non-www pages show up as their www version instead.

Is any of this code redundant? What should I change in order to get a HTTP 200 result for my root?

3
  • @LazyOne So should I instead have my .htaccess include that line "RewriteRule ^$ /index.html [L]" at the end or should I replace my last two lines? Thank you! <3
    – Virage
    Jun 17, 2011 at 21:22
  • Add it at the end. In this case if someone hits http://yourdomain.com/ he still will be redirected to a proper domain first.
    – LazyOne
    Jun 17, 2011 at 21:26
  • Great! I just implemented and it works perfectly, getting a 200 status now! Thanks so much again :D
    – Virage
    Jun 17, 2011 at 21:32

1 Answer 1

4
RewriteRule ^$ /index.html [L]

This will tell Apache to treat the hit to example.com as a hit to example.com/index.html without redirecting (URL stays the same).

The code you already have (last 2 lines) tells Apache to redirect not www-prefixed URL to one with www in front (e.g. http://example.com/somepage.html => http://www.example.com/somepage.html).

1
  • Although this really shouldn't be necessary and is quite possibly just masking an underlying problem. It would be preferable to find out why the redirect was occurring in the first place. Maybe there was a missing L flag on another directive (that would later cause other problems)? Maybe there is a conflict with a mod_alias Redirect (that could also cause further conflicts in the future)? Maybe the DirectoryIndex directive is incorrectly set to an absolute URL? Or maybe there is just a redundant (and undesirable) redirect lurking elsewhere?
    – MrWhite
    May 8, 2018 at 21:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.