Apache RedirectMatch is wonderful

I recently moved my blog from iWeb to WordPress (read this post) and was a bit worried about Google search results pointing to wrong or non-existant content. Reading Google help docs resulted in only a bit of help: I have to set up permanent (301) redirect to my new site and that should do it. The problem is that though I could move my blog to Apache powered server, iWeb and WordPress had a bit different URL layout, with iWeb having .html at the end and folders only to month deep.

But be not afraid – I found a solution with RedirectMatch keyword.

You need Apache

First of all you need Apache as MobileMe does not have methods to do any redirects on their side. So from iWeb set your web to publish to FTP and uploaded it to new server. Then update DNS to reflect the change and verify that it works. This might take some time to propagate through DNS system and browser cache, though.

Write the Redirect

Now, go to the webserver where you uploaded the site and create a .htaccess file at the site root level. Depending on your WordPress settings your milage might wary, but for me, I have URL like /tech/2009/11/24/title/, which corresponds to:

RedirectMatch permanent /en/Programming_tips/Entries/(.*)/(.*)/(..)_(.*).html http://blog.laaz.org/tech/$1/$2/$3/$4

This maps $1 to year, $2 to month, $3 to day and $4 to title of my post. If you do not have so many levels in your URL, just omit the corresponding parts.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s