Have you changed a theme, installed a plugin, or registered a new custom post type and suddenly started seeing 404 errors?
Flushing the rewrite rules makes WordPress regenerate them based on your current permalink settings and the content types registered by your plugins and theme.
This guide explains what rewrite rules are, when you need to flush them, and how to do it using the WordPress admin, WP-CLI, PHP, or the database.
How to Flush Rewrite Rules in WordPress
Flush via WordPress Admin Dashboard (Easiest)
This may not be obvious if you are not familiar with WordPress, but as long as you have admin access, the easiest way to flush the rewrite rules is through the built-in "Permalinks" settings page.
WordPress does not provide a separate control for flushing rewrite rules and it will regenerate the rewrite rules regardless of whether any permalink settings were changed.
- 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.
Flush via WP-CLI Command Line
If you use WP-CLI in your workflow, you can flush the rewrite rules with a single command:
wp rewrite flush
By default, this command refreshes the rewrite rules stored in the database. On an Apache-based server that uses an .htaccess file, add the
--hard
flag to update the file as well:
wp rewrite flush --hard
Reset Rewrite Rules via Database (phpMyAdmin)
If you do not have access to the admin dashboard but can access the database used by the site, you can clear the rewrite rules directly from the database.
The generated rules are stored in the
rewrite_rules
option in the
wp_options
table. The table prefix may differ from
wp_
, so use the prefix configured for your website.
To remove the stored rewrite rules using phpMyAdmin:
- Open phpMyAdmin and select the database used by WordPress.
- Open the
wp_optionstable, replacingwp_with your actual database table prefix (if necessary). - Find the row where option_name is
rewrite_rulesand delete it.
The same result can be achieved using a single SQL query:
DELETE FROM wp_options
WHERE option_name = 'rewrite_rules';
Deleting the stored rules forces WordPress to rebuild them from the current configuration instead of using the previously stored set.
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.
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.
Why Does Flushing Rewrite Rules Fix 404 Errors?
Changes such as installing a plugin, activating a theme, or registering a custom post type or taxonomy can add new URL structures to your website. These changes do not automatically regenerate the rewrite rules used for URL routing.
If a visitor opens a URL that uses a new structure, WordPress cannot determine which content to load from the database. The request then results in a
404 Page Not Found
error.
It is because, WordPress caches rewrite rules in the database to avoid regenerating them on every request. Rebuilding the rules on each request would add unnecessary server overhead and may increase page load time.
Flushing the rewrite rules removes the old URL rules from the database and generates a new set based on the current settings. After regeneration, the new URLs can be recognized and routed to the correct content instead of returning a 404 error.
What If Flushing Rewrite Rules Does Not Fix the 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