Sử dụng add_rewrite_rule để viết lại đường dẫn Phần 2 (ok)

Ví dụ 1: Here is a simple example of how to register a new rewrite rule

// ===========
add_action('init', 'my_book_cpt');
function my_book_cpt() {
  $labels = array(
    'name'               => _x('Books', 'post type general name', 'your-plugin-textdomain'),
    'singular_name'      => _x('Book', 'post type singular name', 'your-plugin-textdomain'),
    'menu_name'          => _x('Books', 'admin menu', 'your-plugin-textdomain'),
    'name_admin_bar'     => _x('Book', 'add new on admin bar', 'your-plugin-textdomain'),
    'add_new'            => _x('Add New', 'book', 'your-plugin-textdomain'),
    'add_new_item'       => __('Add New Book', 'your-plugin-textdomain'),
    'new_item'           => __('New Book', 'your-plugin-textdomain'),
    'edit_item'          => __('Edit Book', 'your-plugin-textdomain'),
    'view_item'          => __('View Book', 'your-plugin-textdomain'),
    'all_items'          => __('All Books', 'your-plugin-textdomain'),
    'search_items'       => __('Search Books', 'your-plugin-textdomain'),
    'parent_item_colon'  => __('Parent Books:', 'your-plugin-textdomain'),
    'not_found'          => __('No books found.', 'your-plugin-textdomain'),
    'not_found_in_trash' => __('No books found in Trash.', 'your-plugin-textdomain'),
  );
  $args = array(
    'labels'             => $labels,
    'description'        => __('Description.', 'your-plugin-textdomain'),
    'public'             => true,
    'publicly_queryable' => true,
    'show_ui'            => true,
    'show_in_menu'       => true,
    'query_var'          => true,
    'has_archive'        => false,
    // 'rewrite'            => array('slug' => 'book','with_front'=>false),
    'capability_type'    => 'post',
    'hierarchical'       => false,
    'menu_position'      => null,
    'show_in_rest'       => true,
    'rest_base'          => 'book',
    'supports'           => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments'),
  );
  register_post_type('book', $args);
  flush_rewrite_rules(true);
}
// ===========
add_action('init', 'my_book_taxonomy', 30);
function my_book_taxonomy() {
  $labels = array(
    'name'              => _x('Genres', 'taxonomy general name'),
    'singular_name'     => _x('Genre', 'taxonomy singular name'),
    'search_items'      => __('Search Genres'),
    'all_items'         => __('All Genres'),
    'parent_item'       => __('Parent Genre'),
    'parent_item_colon' => __('Parent Genre:'),
    'edit_item'         => __('Edit Genre'),
    'update_item'       => __('Update Genre'),
    'add_new_item'      => __('Add New Genre'),
    'new_item_name'     => __('New Genre Name'),
    'menu_name'         => __('Genre'),
  );
  $args = array(
    'hierarchical'      => true,
    'labels'            => $labels,
    'show_ui'           => true,
    'show_admin_column' => true,
    'query_var'         => true,
    'rewrite'           => array('slug' => 'genre'),
    'show_in_rest'      => true,
    'rest_base'         => 'genre',
  );
  register_taxonomy('genre', array('book'), $args);
  flush_rewrite_rules(true);
}
// ====
add_action( 'init', 'pmg_rewrite_add_rewrites' );
function pmg_rewrite_add_rewrites() {
  add_rewrite_rule( 'myparamname/([a-z0-9-]+)[/]?$', 'index.php?myparamname=$matches[1]', 'top' );
}
add_filter( 'query_vars', function( $query_vars ) {
    $query_vars[] = 'myparamname';
    echo '<pre>';
			var_export($query_vars);
		echo '</pre>';
    return $query_vars;
	} 
);
add_action( 'template_include', function( $template ) {
	global $wp_rewrite;
	echo '<pre>';
		var_export($wp_rewrite);
	echo '</pre>';
	var_export(get_query_var( 'book'));
  if ( get_query_var( 'myparamname' ) == false || get_query_var( 'myparamname' ) == '' ) {
    return $template;
  }
  include get_template_directory() . '/template-name.php';
} );

Kết quả:

array (
  0 => 'm',
  1 => 'p',
  2 => 'posts',
  3 => 'w',
  4 => 'cat',
  5 => 'withcomments',
  6 => 'withoutcomments',
  7 => 's',
  8 => 'search',
  9 => 'exact',
  10 => 'sentence',
  11 => 'calendar',
  12 => 'page',
  13 => 'paged',
  14 => 'more',
  15 => 'tb',
  16 => 'pb',
  17 => 'author',
  18 => 'order',
  19 => 'orderby',
  20 => 'year',
  21 => 'monthnum',
  22 => 'day',
  23 => 'hour',
  24 => 'minute',
  25 => 'second',
  26 => 'name',
  27 => 'category_name',
  28 => 'tag',
  29 => 'feed',
  30 => 'author_name',
  31 => 'pagename',
  32 => 'page_id',
  33 => 'error',
  34 => 'attachment',
  35 => 'attachment_id',
  36 => 'subpost',
  37 => 'subpost_id',
  38 => 'preview',
  39 => 'robots',
  40 => 'favicon',
  41 => 'taxonomy',
  42 => 'term',
  43 => 'cpage',
  44 => 'post_type',
  45 => 'embed',
  46 => 'post_format',
  47 => 'rest_route',
  48 => 'sitemap',
  49 => 'sitemap-subtype',
  50 => 'sitemap-stylesheet',
  51 => 'book',
  52 => 'genre',
  53 => 'myparamname',
)
WP_Rewrite::__set_state(array(
   'permalink_structure' => '/%postname%/',
   'use_trailing_slashes' => true,
   'author_base' => 'author',
   'author_structure' => '/author/%author%',
   'date_structure' => '/%year%/%monthnum%/%day%',
   'page_structure' => '%pagename%',
   'search_base' => 'search',
   'search_structure' => 'search/%search%',
   'comments_base' => 'comments',
   'pagination_base' => 'page',
   'comments_pagination_base' => 'comment-page',
   'feed_base' => 'feed',
   'front' => '/',
   'root' => '',
   'index' => 'index.php',
   'matches' => 'matches',
   'rules' => 
  array (
    '^wp-json/?$' => 'index.php?rest_route=/',
    '^wp-json/(.*)?' => 'index.php?rest_route=/$matches[1]',
    '^index.php/wp-json/?$' => 'index.php?rest_route=/',
    '^index.php/wp-json/(.*)?' => 'index.php?rest_route=/$matches[1]',
    '^wp-sitemap\\.xml$' => 'index.php?sitemap=index',
    '^wp-sitemap\\.xsl$' => 'index.php?sitemap-stylesheet=sitemap',
    '^wp-sitemap-index\\.xsl$' => 'index.php?sitemap-stylesheet=index',
    '^wp-sitemap-([a-z]+?)-([a-z\\d_-]+?)-(\\d+?)\\.xml$' => 'index.php?sitemap=$matches[1]&sitemap-subtype=$matches[2]&paged=$matches[3]',
    '^wp-sitemap-([a-z]+?)-(\\d+?)\\.xml$' => 'index.php?sitemap=$matches[1]&paged=$matches[2]',
    'myparamname/([a-z0-9-]+)[/]?$' => 'index.php?myparamname=$matches[1]',
    'category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?category_name=$matches[1]&feed=$matches[2]',
    'category/(.+?)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?category_name=$matches[1]&feed=$matches[2]',
    'category/(.+?)/embed/?$' => 'index.php?category_name=$matches[1]&embed=true',
    'category/(.+?)/page/?([0-9]{1,})/?$' => 'index.php?category_name=$matches[1]&paged=$matches[2]',
    'category/(.+?)/?$' => 'index.php?category_name=$matches[1]',
    'tag/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?tag=$matches[1]&feed=$matches[2]',
    'tag/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?tag=$matches[1]&feed=$matches[2]',
    'tag/([^/]+)/embed/?$' => 'index.php?tag=$matches[1]&embed=true',
    'tag/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?tag=$matches[1]&paged=$matches[2]',
    'tag/([^/]+)/?$' => 'index.php?tag=$matches[1]',
    'type/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_format=$matches[1]&feed=$matches[2]',
    'type/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_format=$matches[1]&feed=$matches[2]',
    'type/([^/]+)/embed/?$' => 'index.php?post_format=$matches[1]&embed=true',
    'type/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?post_format=$matches[1]&paged=$matches[2]',
    'type/([^/]+)/?$' => 'index.php?post_format=$matches[1]',
    'book/[^/]+/attachment/([^/]+)/?$' => 'index.php?attachment=$matches[1]',
    'book/[^/]+/attachment/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1',
    'book/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
    'book/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
    'book/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?attachment=$matches[1]&cpage=$matches[2]',
    'book/[^/]+/attachment/([^/]+)/embed/?$' => 'index.php?attachment=$matches[1]&embed=true',
    '(book)/([^/]+)/embed/?$' => 'index.php?post_type=book&slug=$matches[1]&book=$matches[2]&embed=true',
    '(book)/([^/]+)/trackback/?$' => 'index.php?post_type=book&slug=$matches[1]&book=$matches[2]&tb=1',
    '(book)/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=book&slug=$matches[1]&book=$matches[2]&feed=$matches[3]',
    '(book)/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=book&slug=$matches[1]&book=$matches[2]&feed=$matches[3]',
    '(book)/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?post_type=book&slug=$matches[1]&book=$matches[2]&paged=$matches[3]',
    '(book)/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?post_type=book&slug=$matches[1]&book=$matches[2]&cpage=$matches[3]',
    '(book)/([^/]+)(?:/([0-9]+))?/?$' => 'index.php?post_type=book&slug=$matches[1]&book=$matches[2]&page=$matches[3]',
    'book/[^/]+/([^/]+)/?$' => 'index.php?attachment=$matches[1]',
    'book/[^/]+/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1',
    'book/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
    'book/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
    'book/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?attachment=$matches[1]&cpage=$matches[2]',
    'book/[^/]+/([^/]+)/embed/?$' => 'index.php?attachment=$matches[1]&embed=true',
    'genre/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?genre=$matches[1]&feed=$matches[2]',
    'genre/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?genre=$matches[1]&feed=$matches[2]',
    'genre/([^/]+)/embed/?$' => 'index.php?genre=$matches[1]&embed=true',
    'genre/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?genre=$matches[1]&paged=$matches[2]',
    'genre/([^/]+)/?$' => 'index.php?genre=$matches[1]',
    '.*wp-(atom|rdf|rss|rss2|feed|commentsrss2)\\.php$' => 'index.php?feed=old',
    '.*wp-app\\.php(/.*)?$' => 'index.php?error=403',
    '.*wp-register.php$' => 'index.php?register=true',
    'feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?&feed=$matches[1]',
    '(feed|rdf|rss|rss2|atom)/?$' => 'index.php?&feed=$matches[1]',
    'embed/?$' => 'index.php?&embed=true',
    'page/?([0-9]{1,})/?$' => 'index.php?&paged=$matches[1]',
    'comments/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?&feed=$matches[1]&withcomments=1',
    'comments/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?&feed=$matches[1]&withcomments=1',
    'comments/embed/?$' => 'index.php?&embed=true',
    'search/(.+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?s=$matches[1]&feed=$matches[2]',
    'search/(.+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?s=$matches[1]&feed=$matches[2]',
    'search/(.+)/embed/?$' => 'index.php?s=$matches[1]&embed=true',
    'search/(.+)/page/?([0-9]{1,})/?$' => 'index.php?s=$matches[1]&paged=$matches[2]',
    'search/(.+)/?$' => 'index.php?s=$matches[1]',
    'author/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?author_name=$matches[1]&feed=$matches[2]',
    'author/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?author_name=$matches[1]&feed=$matches[2]',
    'author/([^/]+)/embed/?$' => 'index.php?author_name=$matches[1]&embed=true',
    'author/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?author_name=$matches[1]&paged=$matches[2]',
    'author/([^/]+)/?$' => 'index.php?author_name=$matches[1]',
    '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]',
    '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]',
    '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/embed/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&embed=true',
    '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&paged=$matches[4]',
    '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]',
    '([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]',
    '([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]',
    '([0-9]{4})/([0-9]{1,2})/embed/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&embed=true',
    '([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]',
    '([0-9]{4})/([0-9]{1,2})/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]',
    '([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&feed=$matches[2]',
    '([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&feed=$matches[2]',
    '([0-9]{4})/embed/?$' => 'index.php?year=$matches[1]&embed=true',
    '([0-9]{4})/page/?([0-9]{1,})/?$' => 'index.php?year=$matches[1]&paged=$matches[2]',
    '([0-9]{4})/?$' => 'index.php?year=$matches[1]',
    '.?.+?/attachment/([^/]+)/?$' => 'index.php?attachment=$matches[1]',
    '.?.+?/attachment/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1',
    '.?.+?/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
    '.?.+?/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
    '.?.+?/attachment/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?attachment=$matches[1]&cpage=$matches[2]',
    '.?.+?/attachment/([^/]+)/embed/?$' => 'index.php?attachment=$matches[1]&embed=true',
    '(.?.+?)/embed/?$' => 'index.php?pagename=$matches[1]&embed=true',
    '(.?.+?)/trackback/?$' => 'index.php?pagename=$matches[1]&tb=1',
    '(.?.+?)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?pagename=$matches[1]&feed=$matches[2]',
    '(.?.+?)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?pagename=$matches[1]&feed=$matches[2]',
    '(.?.+?)/page/?([0-9]{1,})/?$' => 'index.php?pagename=$matches[1]&paged=$matches[2]',
    '(.?.+?)/comment-page-([0-9]{1,})/?$' => 'index.php?pagename=$matches[1]&cpage=$matches[2]',
    '(.?.+?)(?:/([0-9]+))?/?$' => 'index.php?pagename=$matches[1]&page=$matches[2]',
    '[^/]+/attachment/([^/]+)/?$' => 'index.php?attachment=$matches[1]',
    '[^/]+/attachment/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1',
    '[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
    '[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
    '[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?attachment=$matches[1]&cpage=$matches[2]',
    '[^/]+/attachment/([^/]+)/embed/?$' => 'index.php?attachment=$matches[1]&embed=true',
    '([^/]+)/embed/?$' => 'index.php?name=$matches[1]&embed=true',
    '([^/]+)/trackback/?$' => 'index.php?name=$matches[1]&tb=1',
    '([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?name=$matches[1]&feed=$matches[2]',
    '([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?name=$matches[1]&feed=$matches[2]',
    '([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?name=$matches[1]&paged=$matches[2]',
    '([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?name=$matches[1]&cpage=$matches[2]',
    '([^/]+)(?:/([0-9]+))?/?$' => 'index.php?name=$matches[1]&page=$matches[2]',
    '[^/]+/([^/]+)/?$' => 'index.php?attachment=$matches[1]',
    '[^/]+/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1',
    '[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
    '[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
    '[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?attachment=$matches[1]&cpage=$matches[2]',
    '[^/]+/([^/]+)/embed/?$' => 'index.php?attachment=$matches[1]&embed=true',
  ),
   'extra_rules' => 
  array (
  ),
   'extra_rules_top' => 
  array (
    '^wp-json/?$' => 'index.php?rest_route=/',
    '^wp-json/(.*)?' => 'index.php?rest_route=/$matches[1]',
    '^index.php/wp-json/?$' => 'index.php?rest_route=/',
    '^index.php/wp-json/(.*)?' => 'index.php?rest_route=/$matches[1]',
    '^wp-sitemap\\.xml$' => 'index.php?sitemap=index',
    '^wp-sitemap\\.xsl$' => 'index.php?sitemap-stylesheet=sitemap',
    '^wp-sitemap-index\\.xsl$' => 'index.php?sitemap-stylesheet=index',
    '^wp-sitemap-([a-z]+?)-([a-z\\d_-]+?)-(\\d+?)\\.xml$' => 'index.php?sitemap=$matches[1]&sitemap-subtype=$matches[2]&paged=$matches[3]',
    '^wp-sitemap-([a-z]+?)-(\\d+?)\\.xml$' => 'index.php?sitemap=$matches[1]&paged=$matches[2]',
    'myparamname/([a-z0-9-]+)[/]?$' => 'index.php?myparamname=$matches[1]',
    'category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?category_name=$matches[1]&feed=$matches[2]',
    'category/(.+?)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?category_name=$matches[1]&feed=$matches[2]',
    'category/(.+?)/embed/?$' => 'index.php?category_name=$matches[1]&embed=true',
    'category/(.+?)/page/?([0-9]{1,})/?$' => 'index.php?category_name=$matches[1]&paged=$matches[2]',
    'category/(.+?)/?$' => 'index.php?category_name=$matches[1]',
    'tag/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?tag=$matches[1]&feed=$matches[2]',
    'tag/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?tag=$matches[1]&feed=$matches[2]',
    'tag/([^/]+)/embed/?$' => 'index.php?tag=$matches[1]&embed=true',
    'tag/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?tag=$matches[1]&paged=$matches[2]',
    'tag/([^/]+)/?$' => 'index.php?tag=$matches[1]',
    'type/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_format=$matches[1]&feed=$matches[2]',
    'type/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_format=$matches[1]&feed=$matches[2]',
    'type/([^/]+)/embed/?$' => 'index.php?post_format=$matches[1]&embed=true',
    'type/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?post_format=$matches[1]&paged=$matches[2]',
    'type/([^/]+)/?$' => 'index.php?post_format=$matches[1]',
    'book/[^/]+/attachment/([^/]+)/?$' => 'index.php?attachment=$matches[1]',
    'book/[^/]+/attachment/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1',
    'book/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
    'book/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
    'book/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?attachment=$matches[1]&cpage=$matches[2]',
    'book/[^/]+/attachment/([^/]+)/embed/?$' => 'index.php?attachment=$matches[1]&embed=true',
    '(book)/([^/]+)/embed/?$' => 'index.php?post_type=book&slug=$matches[1]&book=$matches[2]&embed=true',
    '(book)/([^/]+)/trackback/?$' => 'index.php?post_type=book&slug=$matches[1]&book=$matches[2]&tb=1',
    '(book)/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=book&slug=$matches[1]&book=$matches[2]&feed=$matches[3]',
    '(book)/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=book&slug=$matches[1]&book=$matches[2]&feed=$matches[3]',
    '(book)/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?post_type=book&slug=$matches[1]&book=$matches[2]&paged=$matches[3]',
    '(book)/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?post_type=book&slug=$matches[1]&book=$matches[2]&cpage=$matches[3]',
    '(book)/([^/]+)(?:/([0-9]+))?/?$' => 'index.php?post_type=book&slug=$matches[1]&book=$matches[2]&page=$matches[3]',
    'book/[^/]+/([^/]+)/?$' => 'index.php?attachment=$matches[1]',
    'book/[^/]+/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1',
    'book/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
    'book/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
    'book/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?attachment=$matches[1]&cpage=$matches[2]',
    'book/[^/]+/([^/]+)/embed/?$' => 'index.php?attachment=$matches[1]&embed=true',
    'genre/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?genre=$matches[1]&feed=$matches[2]',
    'genre/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?genre=$matches[1]&feed=$matches[2]',
    'genre/([^/]+)/embed/?$' => 'index.php?genre=$matches[1]&embed=true',
    'genre/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?genre=$matches[1]&paged=$matches[2]',
    'genre/([^/]+)/?$' => 'index.php?genre=$matches[1]',
  ),
   'non_wp_rules' => 
  array (
  ),
   'extra_permastructs' => 
  array (
    'category' => 
    array (
      'with_front' => true,
      'ep_mask' => 512,
      'paged' => true,
      'feed' => true,
      'forcomments' => false,
      'walk_dirs' => true,
      'endpoints' => true,
      'struct' => '/category/%category%',
    ),
    'post_tag' => 
    array (
      'with_front' => true,
      'ep_mask' => 1024,
      'paged' => true,
      'feed' => true,
      'forcomments' => false,
      'walk_dirs' => true,
      'endpoints' => true,
      'struct' => '/tag/%post_tag%',
    ),
    'post_format' => 
    array (
      'with_front' => true,
      'ep_mask' => 0,
      'paged' => true,
      'feed' => true,
      'forcomments' => false,
      'walk_dirs' => true,
      'endpoints' => true,
      'struct' => '/type/%post_format%',
    ),
    'book' => 
    array (
      'with_front' => true,
      'ep_mask' => 1,
      'paged' => true,
      'feed' => true,
      'forcomments' => false,
      'walk_dirs' => false,
      'endpoints' => true,
      'struct' => '/%book_slug%/%book%/',
    ),
    'genre' => 
    array (
      'with_front' => true,
      'ep_mask' => 0,
      'paged' => true,
      'feed' => true,
      'forcomments' => false,
      'walk_dirs' => true,
      'endpoints' => true,
      'struct' => '/genre/%genre%',
    ),
  ),
   'endpoints' => 
  array (
  ),
   'use_verbose_rules' => false,
   'use_verbose_page_rules' => true,
   'rewritecode' => 
  array (
    0 => '%year%',
    1 => '%monthnum%',
    2 => '%day%',
    3 => '%hour%',
    4 => '%minute%',
    5 => '%second%',
    6 => '%postname%',
    7 => '%post_id%',
    8 => '%author%',
    9 => '%pagename%',
    10 => '%search%',
    11 => '%category%',
    12 => '%post_tag%',
    13 => '%post_format%',
    14 => '%sitemap%',
    15 => '%sitemap-subtype%',
    16 => '%sitemap-stylesheet%',
    17 => '%book%',
    18 => '%book_slug%',
    19 => '%genre%',
  ),
   'rewritereplace' => 
  array (
    0 => '([0-9]{4})',
    1 => '([0-9]{1,2})',
    2 => '([0-9]{1,2})',
    3 => '([0-9]{1,2})',
    4 => '([0-9]{1,2})',
    5 => '([0-9]{1,2})',
    6 => '([^/]+)',
    7 => '([0-9]+)',
    8 => '([^/]+)',
    9 => '(.?.+?)',
    10 => '(.+)',
    11 => '(.+?)',
    12 => '([^/]+)',
    13 => '([^/]+)',
    14 => '([^?]+)',
    15 => '([^?]+)',
    16 => '([^?]+)',
    17 => '([^/]+)',
    18 => '(book)',
    19 => '([^/]+)',
  ),
   'queryreplace' => 
  array (
    0 => 'year=',
    1 => 'monthnum=',
    2 => 'day=',
    3 => 'hour=',
    4 => 'minute=',
    5 => 'second=',
    6 => 'name=',
    7 => 'p=',
    8 => 'author_name=',
    9 => 'pagename=',
    10 => 's=',
    11 => 'category_name=',
    12 => 'tag=',
    13 => 'post_format=',
    14 => 'sitemap=',
    15 => 'sitemap-subtype=',
    16 => 'sitemap-stylesheet=',
    17 => 'book=',
    18 => 'post_type=book&slug=',
    19 => 'genre=',
  ),
   'feeds' => 
  array (
    0 => 'feed',
    1 => 'rdf',
    2 => 'rss',
    3 => 'rss2',
    4 => 'atom',
  ),
))
'book-1'

Ví dụ 1: Here is a simple example of how to register a new rewrite rule

Last updated