WordPress URL rewriting

When reviewing Google Analytics this morning I noticed a 404 page view for: http://simeonpilgrim.com/404/blog/2007/07/17/curse-of-the-azure-bonds/

with the refer on the end of the URL, going to the referring web site their is a link to this none existing page but the content was for this page: http://simeonpilgrim.com/blog/2005/08/04/curse-of-the-azure-bonds/

After a bit of reading I found mod_rewrite (Linux hosting) was the tool to fix the problem.

I downloaded the /blog/.htaccess file and used the above mentioned manual to decode the meaning and start hacking me a new file.

Much wasted time latter, I worked out that WordPad was messing with the Unix new-line markers, and changing to Visual Studio was met with success (or lack of server failure).

So what I needed to add was the following line to my Wordpress default .htaccess

RewriteRule ^2007/07/17/curse-of-the-azure-bonds/$ 2005/08/04/curse-of-the-azure-bonds/ [R=permanent,L]

giving me this file

# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /blog/ RewriteRule ^2007/07/17/curse-of-the-azure-bonds/$ 2005/08/04/curse-of-the-azure-bonds/ [R=permanent,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /blog/index.php [L] </IfModule> # END WordPress

And magically the link now redirects to the correct page.

You can find these pages in Google Analytics by:

  • selecting Content

  • selecting Top Content or *Content by Title
    URL rewriting: Steps 1- 2

  • entering /404/ in the Find URL search box
    URL rewriting: Step 3

Happy Fixing…