After a fresh install of WordPress there are a few things we may want to configure before making the site public. The first thing we will want to fine-tune will probably be the default settings of the Permalinks.

Permalinks are the urls pointing to your blog’s articles and pages. WordPress permalinks, out of the box, look a bit weird:

Now, what is p=3? Well, the meaning is quite clear for the WordPress engine: it is a post with an internal ID of 3, for us humans, though, it looks like gibberish.

It’s advisable, therefore, to configure permalinks to use a more human readable style:

Let’s see how to do that.

Allow URL rewrites in Apache

To use more user friendly urls we need the help of the Apache module mod_rewrite. When we enable this module the server takes the urls that we send and converts them to a different url (using a set of defined rules). In this way we can send to the server a url like http://mysite/wordpress/name-of-the-post and have the server serve the http://mysite/wordpress/?p=3 url.

The first thing we need to do, therefore, is to enable the mod_rewrite module.

Edit your httpd.conf:

vi /usr/local/etc/apache24/httpd.conf

Uncomment this line to load the mod_rewrite module:

LoadModule rewrite_module libexec/apache24/

As we have mentioned before we need to define some rewrite rules so that the server knows how to map one url to another: we can define these rules in the .htaccess file.

In the httpd.conf there is an Apache directive that controls which directives in the .htaccess can override the directives defined earlier.
By default the value of AllowOverride is set to None: which means that all directives defined in .htaccess files are going to be ignored. Since we are planning to write our rewrite rules in an .htaccess file we need to change that setting.

Look for the section and change the value of AllowOverride from None to All:

<Directory "/usr/local/www/apache24/data">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted

Restart Apache to apply the changes made:

service apache24 restart

Create the .htaccess File

Go to your WordPress directory:

cd /usr/local/www/apache24/data/wordpress

Create the .htaccess file and set the file ownership to www:

touch .htaccess
chown www:www .htaccess

Configure permalinks

Log-in as administrator to your WordPress site and go to the settings menu:
WordPress settings

Select the Permalinks option:
Select Permalinks

Now you can configure the format you want the Permalinks to use. There are various predefined formats involving the date the post was published and/or the title of the post. But if none of the predefined styles suits you, you can define a custom one:
Choose link format

Surely you did notice that we created before an empty .htaccess file, but that we have still to add a single rewrite rule to it. When select the permalink settings and save, WordPress will try to add the necessary rules to the .htaccess file. If the file permissions of .htaccess file do not allow WordPress to modify the file, we will get a warning  and we will have to manually copy the rewrite rules generated by WordPress.

Save your settings and try to view a post: if everything is correct, you will notice how the url link has changed as displayed in the image below:
Check post url

Thanks for reading. If you found this post useful you can subscribe to my blog to be notified of new posts.