WordPress 404 errors

How To Fix Broken Permalinks In WordPress.
WordPress is a powerful CMS. Sometimes a slight tweak can make your website inaccessible. Another common problem that most WordPress users face at some point is WordPress posts returning a 404 Error. In this article we will show you how to fix WordPress posts returning 404 error.

Usually in this scenario a user can access their WordPress admin area, their blog’s main page, but when accessing a single posts they get a 404 Not found error. First of all, don’t panic most of the time your posts are still there and completely safe. This usually happens if your .htaccess file got deleted or something went wrong with the rewrite rules. What you need to do is fix your permalinks settings. There are several sites describing this, below is the summary of what you actually need to do.

UPDATE JULY 2021: “Still haven’t found what I’m looking for”… so I wrote my own htaccess_keeper plugin. It runs on the normal homepage of the website to save the htaccess to a backup file (when changed), and restores it when a zero bytes file has been detected. It also shoots of an e-mail to the admin that it had to jump to the rescue again!
Interested in this plugin? It is for sale, just contact My Brain.

Check your .htaccess file

First of all, log in with FTP and check your .htaccess file in the root. If it is 0 bytes then the fastest way to recovery is to restore the file from a backup. Please let me know if you find out why this happens, because despite all the descriptions and attempts written below, this was the actual cause of my issues with various WordPress websites breaking randomly.
Also read this … a way to prevent any corruption may be by changing the permission within CPanel on the file .htaccess to 444. Good luck!

Fix your permalinks

if you use a plugin to hide your login and admin pages, the first step is to disable this plugin. I do this in CPanel by renaming the public_html/wp-content/plugins/plugin-folder-name/ to …/someothername/

Next step is to go to Settings » Permalinks, and simply click on Save Changes button.

This will update your permalinks settings and flush rewrite rules. In most cases this solution fixes the WordPress posts 404 error.

Or use another solution:

Keep on reading, there are other ways of solving this 404 issue.

So, if the above did not work for you, then you probably need to update your .htaccess file manually. Login to your server using FTP, and modify the .htaccess file which is located in the same location where folders like /wp-content/ and /wp-includes/ are located. The easiest thing you can do is to temporarily make the file writeable by changing the permissions to 666. Then repeat the original solution. Don’t forget to change the permissions back to 660. You can also manually add this code in your .htaccess file:

# 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

Fix for Local Servers
Sometimes designers and developers install WordPress on their computers using a local server for testing purposes. If you want to use pretty permalinks, then you need to enable the rewrite_module in the Apache configuration of your MAMP, WAMP, or XXAMP.

Reset WordPress -permalinks in the database

The next bit is in Dutch (thank you daddy) and describes if you want to solve this problem by changing a field/value in the database:

Het gebruik van aangepaste WordPress -permalinks kan de optimalisatie van zoekmachines (SEO) verbeteren en de URL van je website aantrekkelijker maken voor zoekopdrachten. WordPress -permalinks zijn de permanente URL’s voor je berichten en pagina’s. Indien nodig kun je WordPress-permalinks terugzetten naar hun standaardinstelling in de database.

  1. Je moet altijd een back -up van je site maken voordat je problemen oplost.
  2. Log in op phpMyAdmin ( cPanel / Plesk / Webhosting / Beheerde WordPress ). Opmerking: in cPanel Hosting moet je de database voor je WordPress-site in de linkerkolom selecteren voordat je doorgaat naar de volgende stap.
  3. Klik op de wp_options tafel.
  4. Zoek de vermelding permalink_structure in de kolom option_value.
  5. Klik op de knop Bewerken.
  6. Verwijder de tekst onder het veld option_value voor deze invoer en laat deze leeg.
  7. Klik op Ga.
  8. De URL op de pagina’s van je website moet de standaard permalink -instellingen voor WordPress weergeven.

Things That Can Break Permalinks In WordPress

There are however, a few things that can break permalinks in WordPress. Let’s take a quick look at them.

1. Installing New Plugins

If you install a new plugin that tries to deal with permalinks, you may enocounter an incompatibility that ends up breaking your permalinks.

2. Updates

Whether you update WordPress core, a plugin or your theme, this can actually break your permalinks if you’re unlucky.

It could for example be the result of an incompatibility between the theme or a plugin and the new version of WordPress, or incompatibilities between the new version of the theme or plugin you updated and other plugins.

3. Migrating Site/Restoring Back Up

If you are migrating your site to a new domain or server, or restoring a back up, you can end up breaking your permalinks.

You can do this if you’re using a plugin or service and you face an unexpected bug/error. Or if you do it manually and make a small mistake.

If you a migrating to a new server and you are getting issues, it is quite likely that your issues have to do with the FTP permissions of your .htaccess file. (If this is you, jump to the changing permissions of your .htaccess file section.)

4. File Permissions Or Other Changes To .htaccess File

Your .htaccess file is basically a file that decides who/what gets to do see/use what files on your site. Lately people might focus on how it can be used to defend against bots and other malicious attacks, but it is also what is used to create permalinks in WordPress.

If the file itself has been changed, or even just the file permissions for the .htaccess file, it can completely break your permalinks.

Sometimes file permissions can change without apparent reason. Maybe your host implemented a site-wide sweep, changing permissions on every file of every client in an attempt to improve overall security.

So if you did not update anything or migrate, or restore a backup, you may want to jump straight to the .htaccess section of this tutorial.

How To Fix Broken Permalinks In WordPress

All you need to fix broken permalinks is access to your WP Dashboard, FTP credentials to access your server, and a little bit of patience.

1. Reset Your Permalink Settings

The first thing you want to do if you’re having this issue, is to simply reset your permalink settings.

This is simply to double check that it’s an actual issue, and not just a small stutter that might have occured during updating or migrating.

Simply log into your WP Dashboard, then go to the permalinks settings. Change your settings away from the standard setting, for example to numeric, then save changes. Now simply select your standard setting again, and save the changes.

Now go back to your site, and try to go to any of your posts and pages. Do they show up as they should, or do they show a “Page Not Found” or 404 error?

If they show up as they should, good news.. your problem was likely a stutter caused by a temporary conflict or minor bug.

If you keep getting the error, you should keep following the steps until the problem is solved.

2. Check And Fix Problems With Your .htaccess File

First off, you need to find your FTP credentials. Then all you need to do is open an FTP Client (like FileZilla) and connect to your website via ftp using your FTP credentials. (Usually ftp.yourdomain.com)

Now head over to the root folder of your WordPress site, and right click your .htaccess file. You should see the option for “file permissions”. If they don’t show 644, set them to 644. Now go back to the permalink settings on your site and try to change the settings and save the changes once more.

Check your page again, still getting an error?

Time to check out the insides of your .htaccess file. Download the file, and open it up.

If you have the W3TC plugin installed, your file should look more or less exactly the same as this:

Even if you don’t, you should at least have the highlighted part in your .htaccess file.

If you don’t, the easiest way to fix this, is to set the file permissions to 666, then reset the permalink settings, and then change your file permissions back to 644.

If you download your .htaccess file again and open it, you should be able to see the highlighted part. If not, you can copy and paste the appropriate code from this codex page.

Try to reset the settings again and visit a post or page. More than likely this will finally fix your website. But if you’re still getting a 404 error, don’t despair.

3. Find And Fix Plugin Conflicts

Another thing that could be causing your permalinks to not work, could be a plugin conflict.

For example a plugin that deals with 403 redirects or some such things.

If you do not have an overwhelming amount of plugins, an easy way to check for and fix this problem, is simply disabling plugins one by one.

First, disable a plugin, then go over to permalink settings and reset the settings again. Now try again to see if your pages show up as they should. No? Disable the next plugin and try again.

One thing to note is that it could be that it is not one plugin that is causing the problem, but more than one plugin with incompatibilities working in tandem finally creating a big problem.

Once you have identified the plugin that seemed to be responsible for stopping you from setting permalinks, you can try to reactivate it. It may not affect your permalinks when they have actually been set, but may need to be deactivated for you to be able to set your permalinks.

Obviously, this is not an ideal way for plugins to interact with your site, but if you are absolutely dependent on this plugin, and there is no good alternative available, it is possible to simply use that as a termporary solution with future updates.

Conclusion

I hope that you found the solution to your permalink/404 page error problem in this tutorial.

Finally…

When everything is in working order again, do not forget to tighten your security again. Rename the plugin-folder back to what is was and in the WP Admin » Plugins, enable the plugin again. Your settings should be unchanged and your login page will be hidden again.

That’s all folks!
Have a nice day…