Changing your permalink structure

I recently changed the permalink structure of this WordPress blog, going from /%year%/%monthnum%/%day%/%postname%/ (WordPress default i think) to the much more elegant and simple /%postname%/. This is very cool ofcourse, both because it's simpler and SEO wise, but on an existing blog, this leaves you with lots of links that point to the wrong URL. If you're running your blog on Apache, the solution is quite simple, if you can tweak your .htaccess file or your Apache config.

The solution can be found in one single RedirectMatch line. This line should be placed above the WordPress code, or in the Apache config. The line is the following:

RedirectMatch 301 /([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ 
http://www.example.com/$4

This matches every URL which starts with a date, and permanently redirects it to the new URL for this post. Ofcourse you could be running your blog in a subdirectory, like I am, in that case, the line would be:

RedirectMatch 301 /subdir/([0-9]+)/([0-9]+)/([0-9]+)/(.*)$
http://www.example.com/subdir/$4

This way, all your incoming links will still work, and thus count for SearchEngines and you have the benefits of the new URL structure.

Comments closed, if you feel you have something to say:
drop me a line.

2 Trackbacks to “Changing your permalink structure”