Skip to main content

Fix 404 errors in WordPress

A 404 error means the server was reached but could not find anything at that address. In WordPress, it shows up in two quite different ways: every post and page except the home page returns 404, or just a few addresses do. This guide helps you tell which one you have and fix it. It is for site owners who can use the dashboard and, for some steps, connect with SFTP.

Which problem do you have?​

What you seeLikely causeGo to
The home page works, but every post and page returns 404The rewrite rules are missing or not workingResave the permalinks
Only certain addresses return 404The content was deleted or its address changedMissing or moved pages
Images or files return 404The files are missing or in the wrong folderCheck the file location with SFTP

How WordPress addresses work​

WordPress pages do not exist as separate files on the server. A permalink such as https://example.com/opening-hours/ is only a readable address. Rewrite rules on the web server pass every such request to WordPress's index.php, which then looks up the right content. If those rules are missing, the server looks for a real folder called opening-hours, finds nothing, and returns 404.

This is the quickest fix and often enough.

  1. Sign in to the dashboard and open Settings > Permalinks.
  2. Without changing anything, choose Save Changes.
  3. Open one of the broken posts again in a private browser window.

Saving tells WordPress to rebuild its rewrite rules and, on Apache servers, to write them to the .htaccess file if it can.

Check the .htaccess file​

On servers that run Apache or a compatible web server, the rewrite rules live in a file called .htaccess in the site's main folder, next to wp-config.php. Its name starts with a dot, so your SFTP client may hide it; turn on "show hidden files". See Redirects and .htaccess.

  1. Connect with SFTP and download a copy of .htaccess, if it exists, as a backup.

  2. Open it in a plain text editor. If it is missing, create a new file called .htaccess.

  3. Make sure it contains the standard WordPress block:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    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]
    </IfModule>
    # END WordPress
  4. Save the file, upload it, and test the site again.

If WordPress is installed in a subfolder, such as https://example.com/blog/, change RewriteBase / to RewriteBase /blog/ and the last rule to /blog/index.php.

Keep any other rules in the file, such as redirects or security rules, but put them outside the # BEGIN WordPress and # END WordPress lines. WordPress may rewrite everything between those lines.

Mistakes in .htaccess can take the site down

A typing error in .htaccess usually causes a "500 Internal Server Error" on every page. If that happens, upload your backup copy again.

mod_rewrite​

The block above relies on an Apache module called mod_rewrite. Almost every host that supports WordPress has it turned on. If the rules are correct and pages still return 404, ask your host to confirm that mod_rewrite is enabled and that .htaccess files are allowed to change rewrite settings.

Sites on nginx​

The nginx web server does not read .htaccess files. Its rewrite rules live in the server configuration, which you can change on a VPS but usually not on shared hosting. A typical rule for WordPress, inside the site's server block, is:

location / {
try_files $uri $uri/ /index.php?$args;
}

It tells nginx to serve a real file or folder if one exists and otherwise to pass the request to WordPress. Reload nginx after changing its configuration. On shared hosting, contact your host instead.

Missing or moved pages​

If only some addresses return 404, the rewrite rules are working and the content is the problem.

  • Deleted content. Check Posts and Pages, including the Trash view. Restore the item if it was deleted by mistake.
  • A changed address. Changing a post's slug (the last part of its address), its parent page or the permalink structure changes its address. Old links, bookmarks and search results still point to the old one.
  • Old links. Search engines and other sites may still link to addresses from a previous version of the site.

For content that has moved, add a 301 redirect from the old address to the new one. A 301 tells browsers and search engines that the move is permanent. You can add redirects with a redirect plugin or as rules in .htaccess. See Redirects and .htaccess.

For content that is gone for good, a 404 is the correct answer. Make sure your theme's 404 page helps visitors, for example with a search box and a link to the home page.

Did this article help you?