WordPress Tutorials

How to Fix the WordPress Post Returning a 404 Error Issue

A 404 error appearing when you click on one of your WordPress posts is a strange issue to have, but the solution is fairly straightforward, thankfully. Unfortunately, there’s no clear reason as to why this issue occurs, making it difficult to prevent.

It has to do with your site’s permalink structure, which is partially controlled by the .htaccess file. You’re more likely to experience this issue if you use custom or “pretty” permalinks as opposed to WordPress’ default setting.

That doesn’t mean you shouldn’t use pretty permalinks. It just means your .htaccess file got deleted or corrupted in some way, shape or form, and you need to correct the issue as it’s causing the 404 error to appear in your posts.

Solution #1: Fix the 404 Error by Resetting Permalinks

This issue is typically caused by a corrupted .htaccess file, as stated earlier. Yours may have gotten deleted or corrupted somehow, causing this 404 error to appear when you click on a WordPress post.

Thankfully, there’s an easy way to generate a brand new shiny .htaccess file that doesn’t require leaving the WordPress admin area. All you need to do is open the Settings menu, and select Permalinks to navigate to your Permalinks settings page.

Scroll down to the bottom of that page, and click Save Changes. This does a number of different things, including cleaning up your file’s rewrite rules. It should be enough to fix the 404 error in most cases. Continue to the next solution if it doesn’t.

Solution #2: Reset Rewrite Rules Manually to Fix the 404 Error

If the simple two-click solution doesn’t work, you may need to do a little more work and reset your .htaccess file’s rewrite rules manually. You’ll need to access your site through an FTP server to do this. We’ll show you how to connect your site to an FTP server via FileZilla in this tutorial. You can also use Cyberduck.

How to Set Up FileZilla

Note: Feel free to skip these instructions if you have experience using FTP clients.

FileZilla is a computer program you can use to access your site’s files from your own computer using an FTP server. We need to download the software to start out with. Click here to download FileZilla. Make sure you choose a version that’s compatible with your operating system.

Once you install the program on your computer, open it, click File in the menu at the top, and select Site Manager.

Enter your site’s name to label your site’s FTP server, and enter the following settings:

  • Host – Your domain example.com
  • Port – Leave blank.
  • Protocol – FTP – File Transfer Protocol
  • Encryption – Only use plain FTP (insecure)
  • Logon Type – Normal

Enter the username and password you use to access your site’s control panel through your host as your username and password for FileZilla. If your host uses cPanel, use the login credentials you use to access cPanel.

Open the Transfer Settings tab. Tick the box for Limit Number of Simultaneous Connections, and enter 8 as the Maximum Number of Connections. Click Connect to connect to the FTP server.

Manually Resetting Rewrite Rules for the .htaccess File

Open your site’s root directory in FileZilla. This is typically called public_html. If you see folders called wp-admin, wp-content and wp-includes, you’re in the right place. This is where your .htaccess file is located. However, .htaccess is a “dotfile,” which are hidden in some file managers by default.

If you do not see a .htaccess file in your site’s root directory, you may need to force the FTP client to show hidden files. If you’re in FileZilla, click Server in the menu at the top, and select Force Showing Hidden Files.

Once you find your .htaccess file, right-click it, and select File Permissions. You can attempt to fix this issue by making the .htaccess file writable temporarily. Enter 666 as the Numeric Value to do so, and click OK to save that setting.

Click Refresh at the top of FileZilla to refresh your site’s files. Go back into WordPress, open your permalink settings, scroll down to the bottom of the page, and click Save Changes.

Go back into FileZilla, and change the file permissions for .htaccess back to 644 for security purposes. Refresh the FTP client when you’re done.

Solution #3: Adding Code to your .htaccess File

Your .htaccess file should have a specific snippet of code inside of it. If your file has been corrupted in some way and you are unable to create a new one using the simple techniques explained above, you may need to add its original code into it.

Use the instructions above to access your site’s files through an FTP server so you can access your .htaccess file. Once you find it, double-click it to download it to your computer. Open it with a text editor, such as Notepad or TextEdit.

See if this code is in there. Study this code compare it with the code in your file to make sure nothing is missing as the simple omission of a forward slash or other character can cause issues.

Copy and paste this code into your file if it’s missing or if you sense there are issues. You can also replace this code with your current code if you simply wish to see if it will work:

# 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

Save the file.

Uploading the File to Your Site

Again, skip these instructions if you already know how to upload files to an FTP server.

Basically, FileZilla has four panels. Use the bottom two panels. The one on the right contains the root directory for your site. Use the one on the left to navigate to the folder that contains the .htaccess you edited on your computer.

Drag the file from the left panel over to the right panel, overwriting the original file when prompted. Refresh the FTP client, and see if the issue is fixed on your site.

How to Fix the 404 Error on a Local Server

If you are using a local server running on MAMP, WAMP or XXAMP and are experiencing the 404 error issue with your WordPress posts, you may need to enable a module called rewrite_module. This is especially true if you wish to use custom or “pretty” permalinks.

Open the application for your server, and open its menu. Hover over Apache and then Apache Modules. Make sure the rewrite_module is checked. Check it if isn’t. This should fix the permalink issue as well as the 404 error issue.

Solution #2: Editing the Code on Your Local Server

The solution above is a quick way to enable custom permalinks on a local server. If you’re having issues enabling them, do so manually.

Open your server’s folder, and find the Apache folder. Open the Conf folder, and open the httpd.conf file inside of it.

Locate this line, and remove the pound # sign from it:

#LoadModule rewrite_module modules/mod_rewrite.so

Save it, and test your WordPress post to see if the 404 error is gone.

Malware and Help from Your Host

Some users have experienced recurring instances of the 404 error issue as the result of malware, though this is rare. If you go through the steps above and fix the issue only to have it return shortly later, you may want to investigate the possibility of your site having been infected by malware.

The best way to prevent malware is to make sure you are only install highly-rated themes and plugins on your site. You must also keep your theme, plugins and WordPress up to date as much as possible as the updates developers release contain key security fixes.

Check out this guide on how to scan your site for malware if you suspect your site has been affected by malware.

If you simply cannot find a way to fix this issue, consider contacting your host. They may be able to help you identify the issue, pinpoint where it’s located and fix it.

Final Thoughts

The WordPress post returning a 404 error issue can be a little frustrating, but the solution is a lot easier to find than most other issues in WordPress.

There’s no sure fire way to prevent this issue from happening, but if you have access to your site’s server logs, you may be able to pinpoint the exact reason it occurred. Again, knowing this likely won’t prevent the issue from happening again, but it may be nice to know.

Your best bet is to keep everything on your site as up to date as possible, make backups on a regular basis, and keep things secure.

Check out these guides if you want to learn how to keep your site running in tip-top shape:

Lyn

View Comments

  • Great Post!

    Apart from actually fixing the issues that cause 404 errors, I like to use plugins to redirect invalid links to home page. This way, typos in URLs are forgiven instead of losing a reader.

  • Many hours trying different solutions from other blogs/sites.
    Solution #3 worked for us in our local servers.
    (Note that "Solution #3: Adding Code to your .htaccess File" works also for local servers. It may sound obvious to many but not to beginners.)
    Site bookmarked...

    Thanks a lot!

Recent Posts

SeedProd Review: A ‘New-Old’ Plugin to Help You Build Full WordPress Websites

SeedProd is one of the elders of the WordPress ecosystem. It's also a bit of…

6 days ago

Dealing with WordPress RSS Feed Errors: How to Identify and Fix Them

Really Simple Syndication (RSS) feeds are a vital component of the WordPress ecosystem. They act…

2 weeks ago

Top Black Friday and Cyber Monday Deals for 2024

It’s that time of year again when people start revving up their shopping lists, hunting…

3 weeks ago

6 Best WordPress Translation Plugins for a Multilingual Site (2025)

If you clicked on this post, I’m guessing you want to find the best solution…

2 months ago

How to Start an Online Course Using WordPress and LearnDash

Trying to figure out how to start an online course so that you can share…

2 months ago

Teachable Review (2025): Is It the Best Way to Create an Online Course?

Considering using Teachable to create an online course? In our hands-on Teachable review, we'll help…

3 months ago