How to setup WordPress Permalinks on Nginx or Apache2

Installing WordPress is not all to it. For WordPress to function properly, one must make sure all the correct settings are in place. This brief tutorial shows you how to correctly configure Nginx or Apache2 webservers to allow WordPress permalinks.

On this site, we’ve written many detailed tutorials on installing WordPress on Nginx and Apache2. Many of our tutorials written are done so that new students and users don’t experience issues after setting things up.

To read a previous post on installing WordPress, please search our site. There are many well written posts that will help you do that.

Step 1: Setting up Apache2 to allow WordPress Permalinks

To setup Apache2 to allow WordPress Permalinks you first need to enable Apache2 rewrite module. This can be done by running the commands below

sudo a2enmod rewrite

Then restart Apache2 server by running the commands below

sudo systemctl restart apache2.service

After restarting Apache2, go and add the below directory block into Apache2 VirtualHost file for WordPress. On Ubuntu the default file is at

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

The the block below and save the file.

<Directory /var/www/html>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted

The change your changes and restart Apache2

Step 2: Setting up Nginx to allow WordPress Permalinks

The steps above showed you how to do it with Apache2. The ones below show you how to do it with Nginx.

The good thing about Nginx is it’s usually built with its rewrite module enabled so you don’t need to first enable it. All you have to do it add a single rewrite line into the site configuration file and you’re done.

Open WordPress site configuration file, usually at the path below

sudo nano /etc/nginx/sites-available/default.conf

The add the line below to enable rewrite for WordPress permalinks

location / {
    index index.php index.html index.htm;
    try_files $uri $uri/ /index.php?$args;

Save your changes and and restart Nginx webserver and you’re done.

sudo systemctl restart nginx.service

These are the steps the correctly configure Apache2 or Nginx webservers to allow WordPress permalinks.


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.