Wordpress Custom URL Rewrites

admin

Administrator
Staff member
I have links in my site that pass queries to pages that query from an external database. This works fine e.g.

Code:
mysite.com/catalog/?tl=flooring

however i want to rewrite this url to appear as

Code:
mysite.com/catalog/flooring

Ive tried modifying the rewrite rules in wordpress but it always displays the index page

Code:
add_filter('rewrite_rules_array','wp_insertMyRewriteRules');
add_filter('query_vars','wp_insertMyRewriteQueryVars');
add_filter('init','flushRules');

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

// 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;
}