Development Tip: 301 Redirect Code
I've been spending time tweaking my site using search engine optimization techniques. This post deals with the issue of directing the non-www version of your site to the www one. After reading information on a number of boards, I decided that doing this was a good thing. Several reasons include:
- Lost link value and damage to the ranking of your home page due to duplicate content issues. The answer is to point all versions to a single "canonical" version. More information can be found here under "Canonical Issues & Duplicate Content".
- Avoiding a 301 sabotage. Some people are using canonical domains to sabotage competitors in Google. Better to be safe than sorry.
- Because (to me) it just looks better.
OK. WHERE'S THAT CODE?Because I have mod_rewrite, the easiest way to do a 301 redirect is to modify the .htaccess file. I use NotePad to edit it.
Several boards listed the following code (or something similar):
Options +FollowSymLinksRewriteEngine OnRewriteCond %{HTTP_HOST} !^www\.yourwebsitename\.com [NC]RewriteCond %{HTTP_HOST} !^$RewriteRule ^(.*) http://www.yourwebsitename.com/$1 [L,R=301]I found a very good
explanation of this 301 redirection code but after using it and several derivations, all I managed to produce were error pages when I typed in my non-www URL. I finally discovered the problem using an
HTTP Server Response Code Checker. This useful little tool showed me problem. I removed the $1 from the above code (portion in red) and now the redirect works!
I'll post more tips as I whip my
"get paid" site into shape. ;-)
Cammie