In this article I will explain how you can fix 404 errors in WordPress posts and pages.

What is a 404 error in WordPress?

A 404 error is a common problem and it means that the server (where your files are stored) can not find your post or page.

There are mainly three types of 404 error messages:

  • The custom error page that is included in your WordPress theme.
  • A page with a 404 status message directly from the server. This page is not styled by your theme.
  • A blank white page.

Step by Step: How to fix a 404 error in WordPress?

If there is more than one error message, or if the website is not showing your custom 404 page, you should start with option one.

But if this is not the case, and you know that you have moved, renamed or removed content, you can try skipping directly to option two.

  1. Option one: Update your websites permalinks.
    • Basic Troubleshooting.
    • Advanced Troubleshooting.
  2. Option two: Update broken links.
  3. Install the Redirection plugin.

Option one: Update your websites permalinks

A common cause of 404 errors is when our WordPress permalinks are not setup correctly, but we can solve this by re-saving our permalinks settings.

To fix the issue, you first need to login to your WordPress admin area.

In the menu, select Settings and Permalinks.

Go setting and permalinks in wordpress menu

Select the permalink format that you prefer.

To help Search Engines like Google to find and read your content, it is recommended that you select a permalink with a post name, or a category and a post name.

Permaink settings

Select the Save Changes button.

Return to the front of your website and test your links.

Basic Troubleshooting

However if there are still broken links and you are sure that the post and page exists, you can troubleshoot the problem by following these two steps:

  • Temporarily activate one of the default WordPress themes. If the links work when you switch the theme, there is a problem with your old theme. Contact the theme author for help.
  • Deactivate your plugins one by one to see if there are any improvements. We do this test because a plugin may be interfering with the permalinks.
Advanced Troubleshooting

If neither of these steps have helped, you may have to change a setting on your server, so the following instructions will be a little more technical.

To fix 404 errors in WordPress posts and pages you need to edit a system file. If you are not comfortable with editing the file, you can contact the support on your hosting provider and ask them to help you.

Log in to your site using FTP or access your files via your hosting providers control panel.

Go to the root folder and look for a file called .htaccess. The root folder is the folder where your wp-config.php file and the wp-content folder is in.

If you can not see the file, you have to turn on the Show hidden files option. Where this option can be found depends on the program or control panel that you are using.

Find your htaccess file using FTP

Create a copy of the file by downloading it to your computer.

Rename the file on your server to htaccess.old. We need to keep the file just in case we need to restore it.

Open the file on your computer in a text editor and delete all the contents of the file. Next we are going to add the new content.

For a single WordPress installation, you need to copy and paste the following code:

# 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 you are using a Multisite with a subfolder:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
# END WordPress

Or if you are using Multisite with a subdomain:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
# END WordPress

Save the file and upload it to the server.

Return to the Permalinks settings page in the WordPress admin area, and save the settings again. Test your website to see if the links are working.

If the links are working, you can safely delete the backup file htaccess.old from your server.

Option two: Update broken links

A 404 error can also occur if you have removed or moved your content while you still have links that points to the old post or page.

If this is the case, you need to update any broken links to point to the correct post or page.

To find broken links, you can follow our detailed guide on how to find broken links to posts or pages, but also problems like missing images.

Install the Redirection plugin to fix 404 errors

Redirection plugin for wordpress

Redirection is a plugin that lets you create custom redirects and find and fix 404 errors in WordPress posts and pages. With this plugin you can log and monitor all 404 errors that happens on your website.

The plugin is completely free and is used on over a million WordPress sites.

The first step is to download the plugin from the plugin directory and install it.

In the WordPress admin area, select Tools and then Redirection.

On the plugin page, read the brief information and select Start Setup.

On the second page, select the two first options: Monitor permalink changes in WordPress posts and pages and Keep a log of all redirects and 404 errors

Continue the setup:

Redirection plugin setup

Redirection plugin rest api setup.png

If the plugin gives you the green light, finish the setup. Otherwise, follow the instructions from the plugin.

Wait for the plugin to do its magic, and click the Finished button.

Now you can add a new redirect by adding the source URL and a new target URL:

Add a new redirect

In the plugin menu, select 404s to show a list of 404 errors.

This list can help you determine if the links need to be redirected, or if someone only wrote a typo when looking for a specific post or page.

You may also want to learn how to fix error establishing a database connection in WordPress.