WordPress Permalinks with Apache2

WordPress Permalinks with Apache2

One of the most important things done during the process of setting up this blog was creating the permalinks structure.  Instead of the normal and sort of ugly:

http://www.heldit.com/?p=3

URL, this blog has been set up to use a different structure.  You might notice that the URL of the current page is:

http://www.heldit.com/2009/11/architecture/wordpress-permalinks-with-apache2

Which I consider to be the better and more useful URL.  Both links above will actually go to the same page, but the second link is the one that will be displayed and stored in search engines.  For general readability and SEO reasons, the second URL is much more appealing.

Setting this permalink structure up isn’t too difficult, and following a quick guide makes it easier.  I will provide instructions for setting up this structure using virtual hosts with Apache 2.  The first step is to edit the permalink settings via the WordPress admin console.  Navigate to Settings > Permalinks, click the custom option, and then type in:

/%year%/%monthnum%/%category%/%postname%/

This is the permalink structure used in the URL mentioned above, but there are also many more options to customize it further.  These options are described pretty well on the WordPress permalinks page: http://codex.wordpress.org/Using_Permalinks. After saving this new permalinks structure, the console will provide a couple lines to be inserted into the .htaccess file located in the root directory for the blog:

<IfModule>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

This may change based on each individual setup, so I would suggest grabbing it from the permalinks page instead of here.  If no .htaccess file exists in the blog root directory, create it and insert the lines.

The last step is to make sure that the mod_rewrite module is enabled.  This can be done by checking the virtual host file for the site to make sure it contains

RewriteEngine on

under the <VirtualHost> tag, as well as

AllowOverride all

under the <Directory..> tag.

After reloading the Apache 2 config, it is time to test by trying out both links to see if both result in the second URL.  Good luck!

2 thoughts on “WordPress Permalinks with Apache2

Leave a Reply

Your email address will not be published. Required fields are marked *