How to Fix WordPress Posts Returning 404 Not Found

Sometimes you may look at this URL on your browser
When you try to remove index.php out of URL, you get 404 Not Found page. Or for some reasons your site gets 404 Not Found for all links. So below are what I did when I got this situation.

Save your permalink again

First of all, you need to check your permalink in admin settings and save it again.
Go to Settings » Permalinks and just click on Save Changes button

Save your permalink
Save your permalink

This action will rewrite .htaccess file and store permalink structure into the database. In most case, this solution the WordPress 404 Error. If not, you have to check the .htaccess file manually. Using FTP or SSH it up to you and then open the .htaccess file (you might change permission to 666 temporary to edit it). Then add this code to .htaccess file

# 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 this bug still exists. So you need to use next solution to check.

Check Local Server Configuration

This bug causes your Apache does not active rewrite module. So you need to check this module activated or not yet.
Create a test PHP file and invoke phpinfo() function to look at our configuration.
If the module is activated, so it will be the list of Loaded Modules.

Check Local Server Configuration
Check Local Server Configuration

If not, you need to activate it. Open your terminal and type this command:

sudo a2enmod rewrite

And restart your server

sudo service apache2 restart

If still not working, so you need to check further a little bit.
Check your Apache config file. It located in /etc/apache2/apache2.conf
Open it in your editor. I like nano, so I use it to open this file

sudo nano /etc/apache2/apache2.conf

Find to this snippet config:

<Directory "path/to/your/document/root"> 
# ....

AllowOverride None

# ....


And change

AllowOverride None


AllowOverride All

After that restart your server again and check your site URL.
Hope this help!