I have a custom page like this:


/show/ is a WordPress page with a postid of 540. I added a rewrite rule to convert the URL to:


Here's the code I'm using in my theme's functions.php for the rewrite:

add_action( 'init', 'init_custom_rewrite' );

function init_custom_rewrite() {
        'top' );

add_filter('query_vars', 'my_query_vars', 10, 1);

function my_query_vars($vars) {
    $vars[] = 'id';
    $vars[] = 'n';
    return $vars;

Now the URL website.com/show/9999/show-name/ works correctly.

However, now I need to make sure that if someone tries to access the page using the old URL:


... that they will be redirected to the new SEO friendly url:


How do I setup that redirect?

1 Answer 1


I figured it out. I put these rewrite rules in .htaccess:

RewriteCond %{QUERY_STRING} ^id=([^/]*)&n=([^/]*)$ 
RewriteRule ^show/?$ /show\/%1\/%2\/? [R=301,L]
  • You should mark your answer as correct
    – Tunji
    Jan 6, 2017 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.