.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:
1 2 3 4 5 6 7 8 9 | # 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:
1 2 | 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…
Now I have restored my SEO juju, and it shouldn’t be long before Google catches up.
Ranger, out.







Google has caught up, so that’s taken just two weeks. “Not bad for a fatso”.
do you need replace existing code or just add the 301 code underneath the original?
I added the code above the WordPress code, so it looks like this…
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
thanks dude
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!
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!
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.
The following code in a new .htaccess file should work:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.twilight-gossip.com [NC]
RewriteRule ^(.*)$ http://twilight-gossip.com/$1 [L,R=301]
Hope that helps!
Thanks! I’ve just uploaded it to my root folder. I hope it doesn’t take too long for the changes to appear.
Cheers!