I am using:

add_action( 'init', 'add_author_rules' );  
function add_author_rules() {   
        "support/([^/]+)/?", "index.php?category=$matches[1]", "top");   

in the themes/function.php

when I enter the address:


the url changes to:


and the variable is not set:

$category = get_query_var('category');
echo '!'.$category.'!';

both give an empty result

the .htaccess is unchanged and is:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

In case I wasnt clear I want:

/support/funding to remain in the address bar and me to have access to the variable category which would be 'funding' in this case

1 Answer 1


First of all, always develop with debugging enabled so you can see errors. This will reveal the first issue: Undefined variable: matches. Your rule should be in single quotes so it's passed as a string and the $matches variable is not expanded.

The second issue is that there is no category query var, if you're trying to set a default WordPress category, it should be category_name.

This is tested and working in TwentyTwelve theme:

add_action( 'init', 'add_author_rules' );  
function add_author_rules() {   
        'support/([^/]+)/?', 'index.php?category_name=$matches[1]', 'top'

Note that you will not see any change to .htaccess as this is an internal rewrite.

If category is your own custom query var, you need to register query vars with WordPress so it is aware of them, though I would not suggest using just category.

add_filter( 'query_vars', 'wpa_query_vars' );
function wpa_query_vars($query_vars){
    $query_vars[] = 'wpa_category';
    return $query_vars;

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.