404 Errors on WordPress Pages and Posts in Localhost

404 Errors on WordPress Pages and Posts in Localhost

wordpress_404_errors
On WordPress set up in your local machine, when you click on Pages and Posts, they take you to a 404 (Page not found) error page.

This is a common issue for most developers who set up WordPress on their local server.

The common answer that you’ll find online is to go to Settings > Permalinks and Save them again. This will rewrite your .htaccess and you should be good to go.

To solve this, make sure that you’ve got the following covered:

Enable mod_rewrite in Apache

To do this, on an Ubuntu Linux machine, open a terminal and run the following commands:

sudo a2enmod rewrite

If mod_rewrite is already enabled, this command will let you know. If that’s the case, then you can skip this section and go to the next. If not, go ahead and restart your apache server with the following command:

sudo service apache2 restart

Windows users? Here you go: https://tomelliott.com/php/mod_rewrite-windows-apache-url-rewriting

AllowOverride in Apache Configuration

In certain installations (Apache2 on an Ubuntu Linux install, for example), saving permalinks won’t work. Even your .htaccess file will be perfect. This is because Apache2 configuration would be set to override any changes to the structure by default.

To fix this, open up the terminal and go to your Apache configuration folder:

cd /etc/apache2

You’ll need to edit the apache2.conf file to make your changes. I’ll use nano to edit:

nano apache2.conf

Here, look for <Directory /var/www/>

Change “AllowOverride None” to “AllowOverride All

Save and exit the editor. Restart Apache with the following command:

sudo service apache2 restart

Once this is done, get back to your WordPress dashboard, save your permalink settings again to what you want it to be, and try accessing your URLs again.

Did this work for you? Did this not work for you? Let me know in the comments.