If a WordPress page returns a 404 error, first flush the rewrite rules by opening Settings > Permalinks and clicking Save Changes. This refreshes WordPress’s permalink configuration and often fixes 404 errors caused by broken rewrite rules.
Flushing the rewrite rules can resolve 404 errors that appear after changing the permalink structure, installing or updating a plugin or theme, or registering custom post types or taxonomies.
If the 404 error persists after flushing the rewrite rules, the problem may be related to the server configuration or a missing or corrupted
.htaccess
file.
What Are Rewrite Rules in WordPress?
WordPress rewrite rules define how URL structures are connected to content types and database requests. When a visitor opens a permalink, WordPress checks the URL against the available rewrite rules.
If the URL matches a rule, WordPress converts the URL pattern into a query, loads the correct template, and displays the exact page the visitor asked for.
For example, a URL such as:
https://example.com/sample/page
can match the URL structure used by standard pages.
WordPress extracts the page slug and looks for a page with that slug in the database. If a matching page is found, WordPress displays it. If no matching page exists, it returns a 404 error.
For built-in content types such as posts, pages, categories, and tags, WordPress generate rewrite rules automatically. Custom post types and taxonomies also use separate rewrite rules unless they are configured as non-public or set not to use pretty permalinks.
These rewrite rules help WordPress identify the content type from the permalink structure in the requested URL. Based on this information, WordPress can determine where to search for the requested content before running a database query.
How to Flush Rewrite Rules in WordPress
Flushing the rewrite rules refreshes WordPress’s stored permalink configuration and can resolve 404 errors caused by outdated rewrite rules.
WordPress can regenerate the rules when you save the permalink settings, even if you have not changed any settings.
To flush the rewrite rules:
- Open the WordPress admin panel.
- Go to Settings > Permalinks.
- Click Save Changes without changing the permalink settings.

Saving the permalink settings causes WordPress to regenerate its rewrite rules. On Apache servers, WordPress may also update the
.htaccess
rules used to process pretty permalinks.
When Should You Flush Rewrite Rules?
WordPress may need its rewrite rules flushed after changes that affect URL structures or content types. Common examples include:
- Changing the permalink structure through the WordPress permalink settings.
- Adding or modifying custom post types or taxonomies.
- Installing or updating plugins or themes that register or modify URL structures.
- Migrating a WordPress website to another server or hosting environment.
- Changing redirects or other URL-related settings.
Troubleshooting WordPress 404 Errors
How to Tell Whether the Problem Is in WordPress or the Server
The appearance of a 404 error page can help identify whether the problem is caused by WordPress rewrite rules or by the web server configuration.
- If the 404 page uses the normal layout of the website, including the site logo, navigation, and footer, the request probably reached WordPress. A rewrite rules conflict may be responsible.
- If the 404 page contains only basic server-generated text without the website’s styling, the web server may be rejecting the URL before WordPress can process it.
A server-generated 404 error may contain text such as:
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 and WordPress Permalinks
Pretty permalinks require the web server to route clean URLs to WordPress correctly. Apache installations typically use a
.htaccess
file for this purpose, while NGINX installations use server configuration directives instead.
On a standard Apache installation, WordPress can create and update the
.htaccess
file when you save the permalink settings. The file contains rewrite directives that allow Apache to pass requests for WordPress URLs to
index.php
.
If the
.htaccess
file is missing, corrupted, or not writable, WordPress may be unable to update the required rewrite directives. The result can be server-level 404 errors for otherwise valid WordPress URLs.
How to Restore the .htaccess File via FTP
If flushing the rewrite rules does not fix the 404 errors and the website uses Apache, check whether the
.htaccess
file exists in the WordPress root directory. FTP or another file-management method can be used to inspect or recreate the file.
The
.htaccess
file can be missing, modified by a plugin, or inaccessible because of file permissions. If the file does not exist, create a new
.htaccess
file in the same directory as
wp-config.php
and add the standard WordPress directives shown below.

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
The default
.htaccess
rules above are intended for a standard single-site WordPress installation. WordPress multisite or network installations may require different rules, so the standard single-site configuration should not be copied to a multisite installation without checking the appropriate configuration.
For the official WordPress documentation on
.htaccess
, see the WordPress .htaccess documentation.
If the website uses NGINX rather than Apache, an
.htaccess
file will not control URL rewriting. In that case, persistent server-generated 404 errors should be investigated in the NGINX server configuration instead.

Leave a Reply