I am using:
add_action( 'init', 'add_author_rules' );
function add_author_rules() {
add_rewrite_rule(
"support/([^/]+)/?", "index.php?category=$matches[1]", "top");
}
in the themes/function.php
when I enter the address:
http://localhost/support/funding
the url changes to:
http://localhost
and the variable is not set:
print_r($_GET);
$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]
</IfModule>
# 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
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 becategory_name
.This is tested and working in TwentyTwelve theme:
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 justcategory
.