Permalinks on WordPress not working

If you’re setting up an installation of WordPress on a new server or desktop and you’re using Apache2 web server. You may come across a situation that your PermaLinks don’t function as expected.

This situation may well be caused by the fact that you have not configured your Apache2 web server correctly.  There are 4 steps involved to overcome the issue of permalinks on wordpress not working.

Ensure the Apache Module mod_rewrite is configured

The Apache Module mod_rewrite is a rules based rewriting engine to rewrite requested URL’s on the fly.  This is simple enough to install and is done so by executing the following commands in your terminal window

sudo a2enmod rewrtie 
sudo service apache2 restart

Edit your Virtual Host file

Depending on your configuration you will need to edit your Apache Virtual Host file.  For this tutorial I am going to assume you are using the default configuration i.e. You’re using the Virtual Host file that is shipped with Apache2.  You can use any Text editor to edit this file, however in this example I am using nano from the terminal.

sudo nano /etc/apache2/sites-available/000-default.conf

And you need to add

  <Directory />
           Options FollowSymLinks
           AllowOverride All
       </Directory>
       <Directory /var/www/html/>
          AllowOverride All
       </Directory>

Your file should now look something like this.

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port t$
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
       <Directory />
           Options FollowSymLinks
           AllowOverride All
       </Directory>
       <Directory /var/www/html/>
          AllowOverride All
       </Directory>
 # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

Add htaccess to your WordPress Directory

You will now need to add an .htaccess file to your WordPress root directory if one does not already exists.  Again you can do this using any Text Editor, I will do so using nano in the terminal

sudo nano /var/www/html/.htaccess

Add the following lines to the file

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Change the permissions on the htaccess file

sudo chown www-data:www-data /var/www/html/.htaccess
sudo chmod 664 /var/www/html/.htaccess

Restart the web server

sudo service apache2 restart

You should now be able to edit your PermaLink settings within your WordPress settings.

Gary Woodfine

Technical Director at Denizon
Gary is Technical Director at Denizon, an independent software vendor specialising in IoT, Field Service and associated managed services,enabling customers to be efficient, productive, secure and scalable in a way which helps them address and reduce their ecological impact.

Denizon's product line successfully integrate IoT, Artificial Intelligence and Blockchain technology to enable efficient, productive, secure and scalable solutions to help organisations address increasing energy demands, ecological impact and Health & Safety concerns of their staff.

Latest posts by Gary Woodfine (see all)