WordPress Posts 404 Error on Localhost
So, I recently switched to Linux and installed WordPress locally on there.
Everything was fine. My homepage loads correctly, there were no problems with the installation. I tried to change the structure of my permalinks, that’s when I faced a problem.
My posts were giving me 404 errors. None of them was loading.
After some research I found the solution. So, if you are facing anything like this, here’s the quick solution.
How To Fix WordPress Posts 404 Error on Localhost
Basically this happened because the permalinks feature requires the mod_rewrite module enabled. So first we are going to enable that.
Open your Terminal and run this:
sudo a2enmod rewrite
We are not done. We just enabled the mod_rewrite module.
There’s another thing we need to do. Cause when permalink setting changes, WordPress writes it to .htaccess file. So we need to enable it to be able to edit .htaccess file.
To do that, we need to change a small thing.
Open apache2.conf file from /etc/apache2 directory.
Open the file with any text editor and look for this part:
<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride none Require all granted </Directory>
Now change the part where it says AllowOverride. Change ‘none’ to ‘FileInfo’ or ‘all’.
Now it should look like this:
<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride FileInfo Require all granted </Directory>
Save the file. And restart apache service. To do that run this in your terminal:
sudo service apache2 restart
That’s it. You’re done.
Now you can change your permalinks settings anyway you like. You wouldn’t face the 404 error anymore.
If you have any questions, don’t hesitate to ask them through comments. Also, if you know any other way to fix the WordPress posts 404 error on localhost, do share with us.