.htaccess and 302 redirect problems fixed

So I had quite a specific problem. For some reason, http://growlingranger.com was redirecting to http://www.growlingranger.com with a 302 redirect. And, as SEO guru (and friend) Ken Jones from the SEOpsCentre put it, that’s bad SEO juju.

302 means that the address has moved temporarily, and will be back soon. Which in turn meant that my entire site (everything at www.growlingranger.com) was seen by Google and others as temporary. Bad juju indeed.

How do you know this? Well, I downloaded and installed a Firefox plugin called Live HTTP Headers, which does exactly what it says on the packet. It gives you a feed of the HTTP headers as you load a page. And my headers had an ominous 302 redirect.

What I need is for it to be a 301 redirect, which means the address has moved permanently and that any lovely link juice is passed on.

Now I tried everything to fix this, including my DNS entries. Scary stuff indeed. But nothing seemed to work. My hosting is with GoDaddy, so if you’ve also had this problem and you know why it happens then please let me know!

However, we were able to find a fix thanks to Ken Jones and his .htaccess awesomeness.

My .htaccess file already has some WordPress stuff in there, which looks like this:

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

And that’s just doing funky things with my permalinks – how my blog has friendly URLs like http://www.growlingranger.com/2009/02/how-to-use-jquery-with-a-json-flickr-feed-to-display-photos/ instead of http://www.growlingranger.com/?p=455.

What we need to add was a bit of redirect code that takes anything and everything from http://growlingranger.com/ and forwards it permanently to http://www.growlingranger.com/.

And here it is:

RewriteCond %{HTTP_HOST} ^growlingranger.com [NC]
RewriteRule ^(.*)$ http://www.growlingranger.com/$1 [L,R=301]

If you’ve experienced the same problem you can just replace ‘growlingranger’ with whatever your domain is. If you’re successful you’ll get something like this in Live HTTP Headers…

Live HTTP Headers

Now I have restored my SEO juju, and it shouldn’t be long before Google catches up.

Ranger, out.

13 thoughts on “.htaccess and 302 redirect problems fixed

  1. I added the code above the WordPress code, so it looks like this…

    # Begin Ken Jones Code
    RewriteEngine On

    RewriteCond %{HTTP_HOST} ^growlingranger.com [NC]
    RewriteRule ^(.*)$ http://www.growlingranger.com/$1 [L,R=301]


    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    # END WordPress
  2. I’m confused :( If I go to web-sniffer.net it will show the website with a 302 redirect, so I downloaded the firefox plug-in to see what was up and I only saw a 200?
    I’m hosted with GoDaddy and only have an htaccess file in my wordpress blog which is located under twilight-gossip.com/exclusives. Do I need to add another htaccess under my main page? Or do I even need to do anything at all?
    Thanks!

  3. Hey Michl,

    First of all, you have it the other way around. I wanted to include the ‘www’, but you want to exclude it from the URL. So, I’m pretty sure that:

    # RewriteCond %{HTTP_HOST} ^www.twilight-gossip.com [NC]
    # RewriteRule ^(.*)$ http://twilight-gossip.com/$1 [L,R=301]

    needs to be in an .htaccess file in the root of your server. You can just create a new one and upload it to the root via FTP or GoDaddy’s control panel.

    Let me know how you go!

  4. I currently do not have an htaccess file in my root folder. Would I only need to copy and paste the code you have above or do I need to add other stuff?
    Thank you for all your help.

  5. yo man i think there is something wrong with this code that you have given as when i tried it on my site it gave an endless loop is there something that i might have done wrong. i also have godaddy as my host.

  6. Oh, so his problem with GoDaddy exists from 2009 until now!

    I am facing the same problem now. I am no htaccess guru but I guess the below thing redirects http://growlingranger.com to http://www.growlingranger.com with HTTP 301 code.

    RewriteCond %{HTTP_HOST} ^growlingranger.com [NC]
    RewriteRule ^(.*)$ http://www.growlingranger.com/$1 [L,R=301]

    Someone suggested me that instead of doing the above, in the GoDaddy DNS manager, remove the www record (www @) from CNAME records and add it as an A record (www 111.111.111.111) (where the 111s is your IP address)

    Are you still using .htaccess redirection? Have you tried modifying the DNS records?

    I have changed the DNS records today and it may take up to 24 hours for the change to take place. Will post the result here tomorrow.

  7. Heya Fellas I was facing the same problem with go-daddy so i called them i told them that when ever i tried to use :Fetch as Google Bot: tool in webmasters for http://thepregnancycentral.com/ it had some kinda of 301 redirects, i took a couple of screen shots and talked about it with them.
    They told me a static IP would solve this problem and it did after buying the static IP package , my problem was solved within minutes.

    So , if you are facing this problem just buy a static IP for your website to solve it.

    Cheers

  8. A very polite guy at GoDaddy just told me that my 302 redirect problem was due to the fact that GoDaddy were running security tests across the server. He said he could not give me a resolution time, estimating a day but maybe even a week. It depends if they find security stuff that needs more work…

    I’ll wait a week and if no joy will move hosting.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>