How to fix WordPress permalinks not working (Posts returning 404 error)

I have spent a couple of hours today trying to fix WordPress broken permalinks for posts and categories and maybe other resources .

All posts returned 404 errors when I changed the format of my links to the beautiful permalinks instead of classic links with the ugly series of id numbers .

Please note that I was using WordPress 4.7 in my local Ubuntu 16 development machine not on a production server so if this is your case too and you are looking for a solution .Here is what you need to do .

There are many things that can cause your WordPress parmalinks not to work so lets check them one by one .

First you need to have rewrite module enabled .If it not enabled then just open up your terminal and enable it with :

sudo a2enmod rewrite

If you get

Module rewrite already enabled

That is OK .It only means you have the rewrite module enabled .

Now restart your Apache server with

sudo service apache2 restart

If this doesn't solve your problem then continue to the next step .

Open .htaccess file and make sure these lines exist

# 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]

# END WordPress

If not ,then just copy them and save the file then restart Apache with

sudo service apache2 restart

Next you need to open apache2.conf with a text editor

sudo nano /etc/apache2/apache2.conf

Make sure you add sudo then enter your root password .

Look for

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

Then change it to

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

So this is the last thing that helped me save my day .Actually all what we have seen before this last change was alreay set so the solution was changing AllowOverride from None to All.

I hope this solves your problem too and see you in another post .

Note: We also publish our tutorials on Medium and If you prefer reading in these platforms, you can follow us there to get our newest articles.

You can reach the author via Twitter:

About the author

Ahmed Bouchefra
is a web developer with 5+ years of experience and technical author with an engineering degree on software development. You can hire him with a click on the link above or contact him via his LinkedIn account. He authored technical content for the industry-leading websites such as SitePoint, Smashing, DigitalOcean, RealPython, freeCodeCamp, JScrambler, Pusher, and Auth0. He also co-authored various books about modern web development that you can find from Amazon or Leanpub

Get our Learn Angular 8 in 15 Easy Steps ebook in pdf, epub and mobi formats, plus a new Angular 8 tutorial every 3 days.

comments powered by Disqus Protection Status