All posts tagged 301

.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.