Changing your WordPress date 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.

Tags:


Yoast.com runs on the Genesis Framework

Genesis theme frameworkThe Genesis Framework empowers you to quickly and easily build incredible websites with WordPress. Whether you're a novice or advanced developer, Genesis provides you with the secure and search-engine-optimized foundation that takes WordPress to places you never thought it could go.

Read our Genesis review or get Genesis now!

Trackbacks