301 Redirect and htaccess for WordPress
November 4, 2007 · Print This Article
So I told you I’ve been reading John Chow’s eBook and in it he brings up a good point about redirecting your website urls for SEO purposes. Here’s the way I understand it…
Basically, there are two versions of your site, and each on is unique. They are: http://www.yoursite.com and http://yoursite.com
These two urls lead to the same exact place. So basically, you can get people linking to the same site, but through two different urls, which degrades your page ranking for Google. Basically, you’re diluting the number of inbound links into your site and watering down your efforts for search engine optimization. But there’s an easy fix: 301 redirect.
With 301 redirect, you basically set up a rule in your htaccess file that says anyone who types in http:// gets sent to the www version of the site instead. Here’s the code I used:
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
*Replace ‘domain’ with your domain name in both lines.
The final code looked like this:
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]# END WordPress
Once again changing ‘domain’ to your domain name.
Now, as far as I know, this code will only work on a Linux server with the Apache mod-rewrite module enabled. This code worked for me, but it may not work for you, so you may need to search around a bit to find a different version that will work. Daily blog tips has a good guide with different variations of this code in their article How to set up a 301 redirect.
Everyone who’s interested in SEO should be doing this for their site to prevent dilution of their inbound links and help improve their SEO. For more great tips on setting up a 301 redirect, check out John Chow’s article: Setting the preferred domain. Since he’s the one that turned me on to the idea, I think he’s definitely worth checking out. He discusses how to use Google Wemaster Tools to set your preffered domain and why you want to use 301 redirect. There’s also instructions for how to do a 301 redirect on a Windows server in the comments of his article. I’m not sure if it will work, but it may help you out.






Comments
Got something to say?