A "404 error" is a common issue with permalinks, often caused by incorrect rewrite rule settings. Before checking more complex solutions, try resetting the rewrite rules. It is a quick fix that often does the trick.
This problem often comes up after installing a new WordPress plugin or registering a custom post types or taxonomies. With admin access, you can often fix it directly from the WordPress dashboard.
However, if the problem is related to something outside WordPress settings — such as a misconfigured server or an issue with the .htaccess file — you may need to investigate further.
A good first step is flushing the rewrite rules. This makes WordPress refresh its settings and update the server configuration behind the scenes. Since it only takes a few clicks, it is worth trying before exploring more complex solutions.
How to Check if Your Permalinks Are Set Up Correctly?
To see if pretty permalinks are working, try opening a subpage. If you get an error, the way it appears can help you identify the issue.
- If the error page matches the standard layout of your website, including the logo and footer, it could indicate a rewrite rules conflict.
- When an error appears with only basic text and no styling, the incorrect server configuration is likely the cause.
This article will focus on the second option. If you come across a server error, such as the ones listed below, the issue is probably due to a missing .htaccess file or an incorrect NGINX configuration.
The requested URL was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.


Server Configuration
To make the pretty permalink system work, WordPress needs either an .htaccess file (if you're using Apache) or an NGINX configuration file (for NGINX servers). These files help WordPress understand how to process and route clean URLs.
When you install WordPress, it automatically generates a .htaccess file. This file is used by Apache, or by NGINX servers if Apache is set up as the reverse proxy. This file includes important settings that determine how URLs are processed.
Whenever you change the built-in permalink settings or install certain plugins, WordPress updates these settings accordingly. If the .htaccess file is missing or corrupted, WordPress cannot properly update the settings, which could cause server-level "404" errors with URLs.
How Are Rewrite Rules Working?
Rewrite rules are an important part of WordPress since they parse URLs to determine if they match any of the URL formats assigned to content types. These rules are a key part of the URL system, transforming pretty permalinks into database queries that allow WordPress to display the correct content.
You might not even know they exist because they are generated automatically whenever you declare new custom post types or taxonomies. Each content type has its own distinct URL format. This lowers the amount of database requests and helps WordPress to limit the query to items belonging to a single post type or taxonomy.
For example, when a visitor opens the URL shown below, WordPress recognizes it as a page because the URL follows the format typically used by pages.
https://example.com/sample/page

It then looks for a page in the database that matches the extracted "page" slug. If a match is found, WordPress will display the page. If no match is found, a "404 error" will be shown instead.
How to Flush Rewrite Rules?
If you can access your website via FTP, one way to address the "404 errors" is by creating a .htaccess file in the root directory and pasting the default code. However, using the admin dashboard will probably be a faster way to handle the 404 errors than dealing with FTP.
Thankfully, WordPress provides an easy, built-in method to fix this without manually editing any code. Just follow these three simple steps.
Go to "Settings -> Permalinks" admin section
Enable pretty permalinks
Save the settings to flush the rewrite rules and generate .htaccess code
Permalink Settings
If you have just enabled pretty permalinks as outlined in the preceding section of this article, there is no need to proceed further with this step.It is recommended that you begin by flushing rewrite rules to address the issue before attempting more complex solutions.
Flushing the rewrite rules cache may resolve 404 errors caused by plugins or themes updates. It is possible that the issue originated from WordPress utilizing an outdated, cached version of rewrite rules.
To flush the cache, please follow these steps:
- Go to the admin page "Settings -> Permalinks".
- Flush the rewrite rules and clear their cache by clicking "Save changes" even if no change has been made.
At this point, the .htaccess file ought to have been created and the rewrite rules flushed. However, if the issue remains and the 404 error page appears, you may try repeating the procedure manually using FTP.
How to Restore the .htaccess File via FTP?
In order to parse and dynamically handle pretty permalinks, the .htaccess file must be present in the WordPress installation. In a nutshell, .htaccess is the configuration file used to control the Apache server with modules like "mod_rewrite" for permalink rewriting.
In some cases, the .file cannot be saved because of file permissions (CHMODs). The other possibility is that a malfunctioning plugin removed or altered it. Fixing this will need FTP access to the root directory.

The default configuration file code is shown below. If the .htaccess file is not present, you will need to create it manually. Please copy, paste, and save the file with the default contents provided below.
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
Leave a Reply