404 Not Found

WordPress 404 on All Pages? Check the .htaccess File First

Server & Cloud Beginner 👁 5 views 📅 Jun 25, 2026

WordPress permalinks break and show 404s when the .htaccess file is missing or corrupted. Quick fix: reset permalinks or regenerate .htaccess.

Quick Answer

Go to Settings > Permalinks and hit Save Changes. If that doesn't work, regenerate the .htaccess file manually via FTP or cPanel, or check the server's rewrite module is enabled.

Why This Happens

I've seen this at least a dozen times with small business clients. They install WordPress, everything works fine on the default permalink structure (ugly URLs with ?p=123), then they switch to a pretty permalink like /post-name/ or /%postname%/ – and boom, every page except the homepage returns a 404.

The problem is almost always the .htaccess file. WordPress needs it to rewrite URLs. If the file is missing, not writable, or the Apache module mod_rewrite isn't on, the server can't translate nice URLs to the real WordPress files. Sometimes it's because a security plugin or caching plugin overwrote the file, or the admin accidentally deleted it. Another common cause: moving WordPress from one server to another without updating permalinks.

I once had a client who spent two hours reinstalling WordPress because they thought the database got corrupted. All they needed was to hit Save on the permalink page. Don't be that person.

Fix Steps (Start Here)

  1. Reset Permalinks in WordPress Admin
    Log into your site's admin panel. Go to Settings > Permalinks. You'll see the current structure selected. Without changing anything, scroll down and click Save Changes. This forces WordPress to rewrite the .htaccess file (if it can write to it). Check if pages work again. This fixes 70% of cases.
  2. Regenerate .htaccess Manually
    If step 1 doesn't help, WordPress might not have write permissions to the root directory. Use FTP or cPanel File Manager to find the .htaccess file in your WordPress root folder (where wp-config.php lives). If it's missing, create a new file named .htaccess and paste this code:
    # BEGIN WordPress
    RewriteEngine On
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    # END WordPress
    Then save and upload. Go back and hit Save Changes in permalinks again.
  3. Check AllowOverride and mod_rewrite
    If the .htaccess exists but still doesn't work, Apache might not be reading it. Open your server's Apache config (often httpd.conf or a virtual host file). Look for a line like AllowOverride None and change it to AllowOverride All in the DocumentRoot directory. Then restart Apache. Also confirm mod_rewrite is enabled – on Ubuntu/Debian, run sudo a2enmod rewrite && sudo systemctl restart apache2. On cPanel, it's usually on by default.
  4. For Nginx Servers
    If you're on Nginx (common with cheap hosts like DreamHost or Kinsta), there's no .htaccess. You need to add rewrite rules in the Nginx config. Add this inside the server block:
    location / {
        try_files $uri $uri/ /index.php?$args;
    }
    Then reload Nginx: sudo systemctl reload nginx. If you're not comfortable editing Nginx configs, ask your host support to add it – they usually do it for free.

Alternative Fixes (If Main One Fails)

  • Disable all plugins via FTP
    Rename the plugins folder to plugins_old in /wp-content/. This turns off all plugins. If the 404 goes away, a plugin was interfering. Reactivate plugins one by one to find the culprit. Security plugins like Wordfence or caching plugins like W3 Total Cache often rewrite .htaccess badly.
  • Switch to default theme
    Change your active theme to a default WordPress theme (Twenty Twenty-Four or similar). Some themes add custom rewrite rules that conflict. If it fixes it, the theme's functions.php has something that breaks permalinks.
  • Check database table prefix
    Rare, but I've seen it. If your database has a non-standard table prefix, sometimes permalink structures stored in the wp_options table get corrupted. Run this SQL via phpMyAdmin: SELECT * FROM wp_options WHERE option_name = 'permalink_structure'; and make sure the value is exactly /%postname%/ or whatever you set.

Prevention Tip

Always take a backup of your .htaccess file before making any changes to permalinks or installing plugins that modify it. I keep a copy in my local Drive labeled htaccess-backup-[date].txt. Also, never delete the .htaccess file thinking WordPress will recreate it – it only does that if the file permissions allow writing. Set your WordPress root folder to 755 and the .htaccess file to 644 so WordPress can update it automatically. And if you move hosts, always re-save permalinks as the first step after migration – before you do anything else.

Was this solution helpful?