How to fix 404 errors in WordPress
When I think about the most frustrating issues I’ve had while working with WordPress, one in particular stands out — 404 Page Not Found errors.
I ran into this quite often when I first started using WordPress and I wasted a lot of time trying to fix it.
It took a while to understand why I was getting these errors — and I see this question asked every couple of weeks — so hopefully this guide will help others struggling with this issue.
Before you start
Before you start trying anything, make sure you have a recent backup available- just in case. While the suggestions below shouldn’t break your site, it’s always a good idea to backup your installation before you start changing server/configuration settings.
In my experience, permalinks are the issue 90% of the time — especially if you’ve recently added a new plugin or theme. Whenever you see a 404 error that doesn’t make sense, the first step is to reset your permalinks.
- Go to your Permalinks Setting Page in the dashboard
2. Click the button labelled Save Changes
What this does is force WordPress to flush your Rewrite Rules. Whenever a request for a page is received by your web server, WordPress will look at the URL and try to determine what content needs to be displayed. It does this internally by comparing the URL against a list of “Rewrite Rules”. Plugins and themes can add additional rewrite rules, but these are not saved until the rules are flushed.
If you’re getting 404 errors when accessing images (or other static files), this is likely to be a server configuration issue. When accessing the page, figure out what the 404 page looks like:
- If the 404 page is a themed page (ie: contains your overall site layout, logo etc), then it appears as the request has been handled by WordPress which is not what we want.
WordPress (in most situations at least) should only handle requests for dynamic content — eg: posts, archives, pages.
Images and static files should be served directly by your web server — WordPress should not be involved.
- Try renaming the .htaccess file in the root folder of your site via FTP/CPanel (this file may be hidden), and resaving your permalinks using the guide above. This will generate a new .htaccess file — the .htaccess file determines what requests WP is responsible for.
- If the 404 page is a plain-looking 404 error page, then make sure the file actually exists on the file system/FTP.
I’ve seen situations where a file has disappeared from the server file system and had to be restored via backup — so always make sure you have backups.
If you have any caching plugins installed, try disabling these. Some caching plugins will add custom rules to your .htaccess file which could possibly cause 404 errors. If you disable caching plugins, backup your .htaccess file and re-save your permalinks (following the above processed) to reset these to their default settings.
If you get to this point and still haven’t resolved your 404 issues, then it’s probably caused by a much deeper issue within the site/server configuration.
Try disabling all of the plugins on your site and re-save your permalinks settings. If the 404 issue disappears, then it’s most likely caused by one of those plugins.
Re-enable them one-by-one to try to determine which plugin is responsible.
Alternatively, post a comment here or on http://reddit.com/r/wordpress — or find a WordPress developer.
Some helpful plugins
The following plugins may help track down the cause of 404 errors:
This post was originally posted at http://hotsource.io/how-to-fix-404-errors-in-wordpress/
For more guides, tips and information visit http://hotsource.io/