brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: wp rewrite list prints the rewrite rules WordPress uses

WordPress
~/tips/tip-wordpress-rewrite-list

wp rewrite list --format=csv

Prints the WordPress rewrite rules and lets you see which one matches a given URL.

A pretty permalink that returns a 404 is annoying to debug when you cannot see the rules behind it. wp rewrite list prints them, so you can check whether the rule you expect exists at all.

wp rewrite list --format=csv

Each line has three columns: the regular expression that is matched against the URL path (match), the query WordPress turns it into (query) and where the rule came from (source), for example a post type, a taxonomy or other for things like the REST API.

To see which rule catches one particular path:

wp rewrite list --match=/2026/11/my-post/

And to look at the rules of one source only, use --source= with the name that appears in the source column.

If a custom post type has no rule in the list, the rules are probably stale. The fix is wp rewrite flush, and --hard also rewrites the .htaccess file. Flushing is cheap, but it should not run on every page load in a plugin, because it rebuilds the rules each time.

The list is read-only, so it is safe to run on a live site. What it shows is what WordPress has registered for that run, which includes rules added by plugins and the theme.

Further reading: wp rewrite list (WP-CLI handbook)

More WordPress tips wp user application-password create anna backup-script --porcelain define( 'MEDIA_TRASH', true ); wp cli check-update wp theme delete --all wp media image-size All WordPress tips (85) All topics

Link