Permalink rewrite fix for WordPress
This site is powered by WordPress running on Ubuntu. Some of you might have noticed we recently changed the permalink structure. Permalinks are the permanent links to the posts or categories in a blog site. Permalink can be used to link to your article or category by other blogs or sites, or to send a link to your story in an e-mail message.
The permalinks now all have the structure /%year%/%monthnum%/%postname%/ where the previous the structure was /%post_id%. Permalink rewrites are based on the Apache Rewrite engine and there are a few caveats when changing the permalink structure. Here’s a checklist to get you going…
First of all, you must make sure that the mod_rewrite module is loaded in your apache instance.
root@export:/var/www/blog# apache2ctl -t -D DUMP_MODULES
and check for
rewrite_module (shared)
If not, checkout the apache document on rewrite engine to enable this module in your apache instance.
Finally, make sure your virtual host configuration has :
RewriteEngine On
When changing the permalink structure in your WordPress backend, it will generate a .htaccess file. This is what it looks like for our permalink structure :
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule># END WordPress
Normally, this is supposed to be the end of the story but when you receive a 404 surfing to your newly generated links, then verify the following two settings in your virtual host configuration :
- The FollowSymLinks option enabled
- FileInfo directives allowed (e.g.
AllowOverride FileInfoorAllowOverride All)
Good luck!
PS: If you don’t want to loose your pagerank for the posts that have incoming links using the old permalink structure, go checkout “Dean’s Permalinks Migration 1.0“. This will redirect the old permalinks to your new structure, and keep Google happy
It is available from the plugins menu in the WordPress backend.
August 2nd, 2009 at 17:03
Good solution, thanks