guillermo, out of repose

Apache 301 Redirects, Google, and WordPress — Make ‘em Work for You

In redesign­ing my blog, I updated the Word­Press perma­link struc­ture so that it would make more sense. Mak­ing that sort of change when there are other sites link­ing to you can be a very big deal if you don’t promptly and prop­erly han­dle the sit­u­a­tion. Here’s how you promptly and prop­erly han­dle the sit­u­a­tion ;) .

If you’re a seri­ous devel­oper & blog­ger and you’re not using Google’s free Web­mas­ter Tools, you should start. No need for me to talk it up any more than that. Thanks to Web­mas­ter Tools, I was quickly able to iden­tify the posts to which peo­ple were link­ing. I used that infor­ma­tion to mod­ify my .htaccess file which, if you don’t already know, plays an incred­i­bly impor­tant role in web devel­op­ment on Apache web servers, espe­cially where SEO is related.

Quick note here: if you feel trep­i­da­cious about mod­i­fy­ing your .htaccess file, embrace that feel­ing. You don’t want to exper­i­ment with it on a live, pub­lic 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 edi­tor, open up your .htaccess file. If you use Word­Press, 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 every­thing there, but that essen­tially routes all of your requests — requests that aren’t for “real” files and direc­to­ries — 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 :

&lt;IfModule mod_rewrite.c&gt;
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/
&lt;/IfModule&gt;

That about does it. Your old links will point to the new ones, and folks like Google will know, because of the 301 direc­tive, the new cor­rect loca­tion of your post (notice that I didn’t include http:// any­where in there — use rel­a­tive links).

For more info, here’s an arti­cle a friend of mine wrote. Also, check out this Word­Press plu­gin that seems to take care of all of this for you — I haven’t yet tried it myself, though.