How to change the format of WordPress permalinks on Raspberry Pi

WordPress LogoIn the new versions of WordPress it is possible to change the format of the permalinks. By default the permalinks are basically made up of a number (“?p=number”) and they don’t look so nice, but you can change them to contain the name of the post for example, the date of the post or they can even have some custom structure:

WordPress Permalinks

WordPress Permalinks

There are mainly two reason why people wish to switch from the default permalink structure to another one:

    1. The default format is a bit ugly and the custom ones are more suggestive
    2. WordPress caching plugins require a non-default permalink format

The best practice is to change the permalink format to the desired one immediately after a WordPress blog is created, however authors tend to change their mind, so the question is how to change the format when there are already some existing posts in the blog without losing the existing links (without getting broken links). Normally this should be as easy as choosing a new permalink format and telling WordPress to use it. Normally WordPress should take care of the old links and everything should be fine. Unfortunately this is not always the case because this behavior depends on the settings of the server which is hosting the WordPress blog. If the settings are not correct, you will get the “404 Not Found” error when you click a previously existing link after changing the permalink format. This means that after switching to the new format, you will need to update some settings on your server.


Steps to change the WordPress permalink format on a Raspberry Pi LAMP server:

1. Log into your WordPress blog and go to Dashboard. After that go to Settings / Permalinks.

2. Select the desired permalink format and click “Save Changes”.

3. On your Raspberry Pi open a command window.

4. Edit the file /etc/apache2/sites-available/default:

    • nano /etc/apache2/sites-available/default
    • find the following two sections:

<Directory />
    Options FollowSymLinks
    AllowOverride None
<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride none
    Order allow,deny
    allow from all

    • Put a “+” sign in front of the “FollowSymLinks” strings and change the “AllowOverride None” lines to “AllowOverride All”. So after the change the two sectios should look like this:

<Directory />
    Options +FollowSymLinks
    AllowOverride All
<Directory /var/www/>
    Options Indexes +FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all

    • Save the file (CTRL+O)

5. Repeat the actions from step 4 for the file /etc/apache2/default-ssl

6. Copy some modules from the /etc/apache2/mods-available directory to the /etc/apache2/mods-enabled directory, in order for Apache to be able to use these modules:

    • cp -p /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled
    • cp -p /etc/apache2/mods-available/expires.load /etc/apache2/mods-enabled
    • cp -p /etc/apache2/mods-available/headers.load /etc/apache2/mods-enabled

Note: The last two modules are only required if you are changing the permalinks because a caching plugin needs it. Otherwise the first module (rewrite) will suffice.

7. Restart Apache:

service apache2 restart

Now when you go to your WordPress blog, your previously existing links should be working even though the permalink format has been changed.



How to change the format of WordPress permalinks on Raspberry Pi — 6 Comments

  1. OK, I followed the steps for setting up permalink and when I change from anything but deafult , I get a 404 error. Thanks!

  2. Thank you. You helped me to solve a problem. I didn’t find this solution on a blog here in France.
    Once again thank you!
    Jacques… Nice France.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.