add_rewrite_rule with trailing slash redirects
just change your rule to this add_rewrite_rule(‘^my-route?$’, ‘index.php?_my_route=1’, ‘top’)
just change your rule to this add_rewrite_rule(‘^my-route?$’, ‘index.php?_my_route=1’, ‘top’)
Have you tried: add_rewrite_rule(‘^search/reviews/?’,’index.php?pagename=search-results’,’top’); instead? (Making the last / optional). If after flushing the rewrite rules that still doesn’t work, check with Monkeyman rewrite analyzier and update the question with your findings.
First you have to filter query vars and add your query var to the array: add_filter( ‘query_vars’, ‘wpa56345_query_vars’ ); function wpa56345_query_vars( $query_vars ){ $query_vars[] = ‘cat_id’; return $query_vars; } Then your rule which captures any digits after your pagename coupons and passes that as cat_id: add_action( ‘init’, ‘wpa56345_rewrites’ ); function wpa56345_rewrites(){ add_rewrite_rule( ‘coupons/(\d+)/?$’, ‘index.php?pagename=coupons&cat_id=$matches[1]’, ‘top’ … Read more
I’m affraid this “nasty” solution would be the most effective than trying to write some cool function that will translate your permalinks into pretty permalinks: $permalink = rtrim( get_permalink( $id ), “https://wordpress.stackexchange.com/” ) . ‘/foo’ . ‘/2’; The rtrim part (removing trailing slash) is just for to be sure there are not going to be … Read more
First, adding a rewrite tag and a query var is redundant, adding the tag adds the query var. Second, $matches corresponds to each regex pattern you have in your rule, so it should be $matches[1] and $matches[2], not 2 and 4. Last, for a single member, you can just set the member query var. add_rewrite_rule( … Read more
add_rewrite_rule works only with one “directory”
plugin_dir_url( __FILE__ ) will return the URL of the current files directory. Usage would be: $url = plugin_dir_url( __FILE__ ) . ‘/newfolder/newfolder/index.php’;
You can use the pattern (([^/]*)/)? to match a full <component>/ construction – this will create a multi-dimensional element in the $matches array, with the first level containing the full expression and the internal matches containing an item with <component> without the “https://wordpress.stackexchange.com/” character. However, you need to be very careful in the way you … Read more
While it’s possible to get rid of WP_Query in WP load process it’s pretty horribly inconvenient to accomplish. 🙂 Let’s recap the process as related to rewrite: Web server takes pretty permalink and rewrites it to WP’s index.php. WP takes “pretty” part and applies its rewrite rules to it, turning it into query variables. Query … Read more
Rewriting base name Taxonomy same Post Type