Permalinks keep reverting to 404 unless I re-save them

I'm running the latest (and constantly updated) version of WordPress on Nginx.

Every now and then I wake up to a site full of 404 errors. The fix is to go into the permalinks and just save the settings on that page. This typically fixes the issue for a day or so.

This was happening to another site of mine on the same server. It suddenly stopped being an issue. My point here is that not only do I not know what's causing it, but I can't even tell what's fixing it.

Topic permalinks nginx 404-error Wordpress

Category Web


Same problem for the last few weeks, using nginx not apache, Switching rule saving, then switching rule back and saving fixes it for a day...


Go to the permalinks settings of your Wordpress site and save as it is. If it is not working check your .htaccess file and add

# 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]
</IfModule>
# END WordPress

While I'm not sure what could be causing your 404 problem, here are some suggestions:

  • Deactivate plugins and see if that fixes the problem. If so, reactivate one at a time until you get the problem again
  • Change to a different theme and see if that fixes it
  • Make sure the .htaccess file isn't somehow getting changed - this file configures how your web server handles requests by routing them to the proper place

Other than that, I couldn't say more of what could be causing this with so little information.

The Fix

You did say that saving the Permalinks Settings fixed the issue but can't tell why. When you visit Permalinks Settings (you shouldn't even have to save), the function flush_rewrite_rules runs. The description from the Codex is pretty straightforward: Remove rewrite rules and then recreate rewrite rules.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.