I have the following custom rewrite rules.
add_action( 'init', 'corse_rewrite_rules', 0 );
function corse_rewrite_rules( ) {
add_rewrite_rule('listings/make/([^/]*)/page/?([0-9]{1,})/?$', 'index.php?post_type=product&product_make_model=$matches[1]&paged=$matches[2]', 'top');
add_rewrite_rule('listings/make/([^/]*)/?$', 'index.php?post_type=product&product_make_model=$matches[1]', 'top');
}
Which should take a URL like this :
/product_make_model/stuff/
to :
/listings/make/stuff/
The issue in hand is that although the Rewrite is working and the new URL is accessible, its not redirecting the old URL to the new one.
If I also add an SEO plugin such as YOAST the canonical URL is listed as the the old URL confirming that there is something wrong.
Could someone shed some light as to what im doing wrong ?
add_rewrite_rule
is the 'old' URL to match and the second argument is the place to redirect to. So I'd expect your functions to try to redirect to/product_make_model/stuff/
. Is that your intention?/listings/make/stuff/
will be redirected to/product_make_model/stuff/
.