Mapping multiple URLs to same page

You can use the same answer as the question you referred to (I have answered it). Here’s how you would change to pass the arguments:

<?php
    add_action('init', 'add_my_rule');

    function add_my_rule()
    {
        global $wp;
        $wp->add_query_var('args');

        add_rewrite_rule('test\/finaldestination\/(.*)','index.php?pagename=about&args=$matches[1]','top');
    }
?>

Assuming ‘finaldestination’ stays the same always, and the pagename (slug) is ‘about’ (you can change both). Apply your custom template to this page, and on the template, do this:

//if you visit http://.../test/finaldestination/name/romeo, then $params will be name/romeo. You can explode this and get the value.
$params = get_query_var('args');

After you put this code in your file, just go to Settings>Permalinks and hit the save button.
I haven’t tried this, but have used something similar in a recent project and I’m sure it will work.

Leave a Comment

tech