Apache 301 Redirects, Google, and WordPress — Make ‘em Work for You
In redesigning my blog, I updated the WordPress permalink structure so that it would make more sense. Making that sort of change when there are other sites linking to you can be a very big deal if you don’t promptly and properly handle the situation. Here’s how you promptly and properly handle the situation
.
If you’re a serious developer & blogger and you’re not using Google’s free Webmaster Tools, you should start. No need for me to talk it up any more than that. Thanks to Webmaster Tools, I was quickly able to identify the posts to which people were linking. I used that information to modify my .htaccess file which, if you don’t already know, plays an incredibly important role in web development on Apache web servers, especially where SEO is related.
Quick note here: if you feel trepidacious about modifying your .htaccess file, embrace that feeling. You don’t want to experiment with it on a live, public site, as errors could turn it into a big, ugly error message.
That being said, let’s get busy on that bad boy:
In your favorite editor, open up your .htaccess file. If you use WordPress, your basic .htaccess file should look a bit like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I won’t get into everything there, but that essentially routes all of your requests — requests that aren’t for “real” files and directories — to your index.php file. We’re going to add one line of code to this file, right above the </IfModule>, and it’ll look like this:
Redirect 301 /your/old/funky/url /your/new/awesome/url
Here’s one from my new .htaccess file:
Redirect 301 /archives/38-windows-xp-xampp-php-and-oracle-10g /2008/09/29/windows-xp-xampp-php-and-oracle-10g/
That’s it. So the new file looks like this :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Redirect 301 /archives/38-windows-xp-xampp-php-and-oracle-10g /2008/09/29/windows-xp-xampp-php-and-oracle-10g/
</IfModule>
That about does it. Your old links will point to the new ones, and folks like Google will know, because of the 301 directive, the new correct location of your post (notice that I didn’t include http:// anywhere in there — use relative links).
For more info, here’s an article a friend of mine wrote. Also, check out this WordPress plugin that seems to take care of all of this for you — I haven’t yet tried it myself, though.