wp rewrite
Lists or flushes the site’s rewrite rules, updates the permalink structure.
See WP Rewrite class reference.
Commands | Description |
---|---|
wp rewrite flush | Flushes rewrite rules. |
wp rewrite structure | Updates the permalink structure. |
wp rewrite list | Gets a list of the current rewrite rules. |
Examples
# Flush rewrite rules $ wp rewrite flush Success: Rewrite rules flushed. # Update permalink structure $ wp rewrite structure '/%year%/%monthnum%/%postname%' Success: Rewrite structure set. # List rewrite rules $ wp rewrite list --format=csv match,query,source ^wp-json/?$,index.php?rest_route=/,other ^wp-json/(.*)?,index.php?rest_route=/$matches[1],other category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$,index.php?category_name=$matches[1]&feed=$matches[2],category category/(.+?)/(feed|rdf|rss|rss2|atom)/?$,index.php?category_name=$matches[1]&feed=$matches[2],category category/(.+?)/embed/?$,index.php?category_name=$matches[1]&embed=true,category
Source code of the commands
wp rewrite flush
Flushes rewrite rules.
Resets WordPress' rewrite rules based on registered post types, etc.
To regenerate a .htaccess file with WP-CLI, you'll need to add the mod_rewrite module to your wp-cli.yml or config.yml. For example:
apache_modules:
- mod_rewrite
Usage
wp rewrite flush [--hard]
You can specify global options and the following:
- [--hard]
- Perform a hard flush - update .htaccess rules as well as rewrite rules in database. Works only on single site installs.
Examples
$ wp rewrite flush Success: Rewrite rules flushed.
wp rewrite structure
Updates the permalink structure.
Sets the post permalink structure to the specified pattern.
To regenerate a .htaccess file with WP-CLI, you'll need to add the mod_rewrite module to your WP-CLI config. For example:
apache_modules:
- mod_rewrite
Usage
wp rewrite structure {permastruct} [--category-base={base}] [--tag-base={base}] [--hard]
You can specify global options and the following:
- {permastruct}
- The new permalink structure to apply.
- [--category-base={base}]
- Set the base for category permalinks, i.e. '/category/'.
- [--tag-base={base}]
- Set the base for tag permalinks, i.e. '/tag/'.
- [--hard]
- Perform a hard flush - update .htaccess rules as well as rewrite rules in database.
Examples
$ wp rewrite structure '/%year%/%monthnum%/%postname%/' Success: Rewrite structure set.
wp rewrite list
Gets a list of the current rewrite rules.
Usage
wp rewrite list [--match={url}] [--source={source}] [--fields={fields}] [--format={format}]
You can specify global options and the following:
- [--match={url}]
- Show rewrite rules matching a particular URL.
- [--source={source}]
- Show rewrite rules from a particular source.
- [--fields={fields}]
- Limit the output to specific fields. Defaults to match,query,source.
- [--format={format}]
Render output in a particular format.
Default: table
Can be:- table
- csv
- json
- count
- yaml
Examples
$ wp rewrite list --format=csv match,query,source ^wp-json/?$,index.php?rest_route=/,other ^wp-json/(.*)?,index.php?rest_route=/$matches[1],other category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$,index.php?category_name=$matches[1]&feed=$matches[2],category category/(.+?)/(feed|rdf|rss|rss2|atom)/?$,index.php?category_name=$matches[1]&feed=$matches[2],category category/(.+?)/embed/?$,index.php?category_name=$matches[1]&embed=true,category