I've links during my site that pass queries to pages that question from an exterior database. This works fine e.g.


however i wish to rewrite this hyperlink to appear as


Ive attempted modifying the rewrite rules in wordpress however it always shows the index page


// Remember to flush_rules() when adding rules
function flushRules(){
    global $wp_rewrite;

// Adding a new rule
function wp_insertMyRewriteRules($rules)
    $newrules = array();
    $newrules['(catalog)/([a-zA-Z0-9 ]+)$'] = '/catalog/?tl=$matches[2]';
    return $newrules + $rules;

// Adding the id var so that WP recognizes it
function wp_insertMyRewriteQueryVars($vars)
    array_push($vars, 'id');
    return $vars;

Rewrite rules in WordPress don't quite work like how you are expecting these to. All rewrite rules map to some file handler (more often than not index.php), not another URL.

This is a reduced code example

$rules['catalog/(.*)/?'] = 'index.php?pagename=catalog&tl=$matches[1]';
array_push($query_vars, 'tl'); // note query var should match your query string

This could map catalog/whatever towards the WordPress page 'catalog', and pass on the query var 'tl'. You can produce a page template for 'catalog', then get the need for 'tl' using get_query_var('tl').

Also stay away from query vars like id - use some thing unique (like 'tl') to prevent clashes with WordPress.

And don't flush rules on every init! It's bad practice, and can email .htaccess and call database updates on every page load!

WordPress will invariably flush permalinks if you update a publish or perhaps your permalink structure (simply improve your permalinks whenever you make changes for your code).

This article over at Raazorlight adopts a little more detail on the entire process of getting querystrings and URL spinning in Wordpress.

Also, look into the comments there to determine why calling flushRules() might not be necessary should you re-save permalinks. Optionally, flushRules() could be known as only once throughout wordpress plugin activation callback.

Digging much deeper, commenter 'pmdci' links to an instructive publish/saga around the related subject of passing a question to some custom publish type utilizing a custom taxonomy.