WordPress : How to fix "not found" error with posts & pages links

Apache 404 Not Found Error with Pretty Permalinks on WordPress

Recently I had some issues with EasyPHP development server, so I decided to install PHP, Apache & MySQL manually on my local machine. After everything was set up, the WordPress website on a localhost loaded without any issue, but when I clicked on any of the post or page links, I got an error telling me that the requested URL was not found. This article will show how I fixed this issue.

The error I was getting was 404 status error:

Not Found
The requested URL ... was not found on this server.

WordPress Pretty Permalink Not Found 404 Error

Luckily, the Admin Dashboard part of the website worked without any issue, so I went to Settings > Permalinks and when I switched permalink to default setting "Plain", the posts and pages opened without any issue, but for any other "pretty permalink" option, for example with "Post name", I was getting the "Not found" error.

In the end it turned out it was an Apache configuration issue. I had to make two changes to the httpd.conf server configuration file.

Enable mod_rewrite module

The WordPress generates a .htaccess file when permalinks are set up and that .htaccess uses mod_rewrite module to rewrite requested URLs on the fly. Looking at the httpd.conf file I immediately noticed that this module was commented out:

Uncommenting the mod_rewrite module was not enough though as after the Apache server restart, the problem still persisted. So I started to compare the httpd.conf of the Apache server with the one that was used by Apache on EasyPHP development server. There were some minor differences, but the most obvious was that my current Apache configuration file was lacking <VirtualHost> directive.

Add VirtualHost directive

I borrowed the <VirtualHost> directive settings from the EasyPHP Apache configuration file and modified the root path, so that they pointed to my www folder ("C:/my_www"):

After restarting Apache, the pretty permalink on WordPress sites started to work again.

But, what was within the <VirtualHost> that fixed the issue with WordPress?

AllowOverride directive

It turns out, the culprit for broken permalinks was the "AllowOverride None" setting inside the <Directory> section. When the AllowOverride directive is set to None, the .htaccess files are ignored including the one created by WordPress. The above code has AllowOverride All inside <Directory> and as a result, it fixes the issue.

Note: If you do have AllowOverride All, but the mod_rewrite is not loaded, we get the 500 Internal Server Error instead of 404 "not found" error.

Conclusion

If links on a WordPress website return 404 not found error, while the admin dashboard works without any issue, the problem lies with the pretty permalinks not being recognized. This is most likely due to configuration issue inside the Apache httpd.conf file. In my case, I had to make sure theĀ mod_rewrite module was getting loaded while also adding a VirtualHost settings with <Directory> section containing AllowOverride All option.

Share this page

Add a Comment

Back to Top