I have created a small function to rewrite a get variable. First, I created the page 'download', and I want a get variable to be used for the file attribute. This is an working URL: http://example.com/download/?file=file
But when I use add_rewrite_rule to make the url look like this: http://example.com/download/file, It doesn't work.
The function:
function createRewriteRules() {
add_rewrite_rule('download/([^/]*)', 'index.php/download/?file=$matches[1]', 'top');
}
add_action('init', 'createRewriteRules');
I have also tried the following:
function createRewriteRules() {
add_rewrite_rule('download/([^/]*)', 'download/?file=$matches[1]', 'top');
}
add_action('init', 'createRewriteRules');
On both, $wp_query returns "file" as pagename instead of "download".
Updated:
function createRewriteRules() {
add_rewrite_tag('%file%', '([^&]+)');
add_rewrite_rule('download/([^/]+)/?$', 'index.php/?pagename=download&file=$matches[1]', 'top');
}
And a reflush doesn't work eighter, while index.php/?pagename=download&file=file does work. The rewrite rule also got added to the .htaccess file.