I agree. I’ve been having the same problem.
Erm…
My code
add_filter('generate_rewrite_rules', 'download_rewrite');
function download_rewrite($wp_rewrite) {
$wp_rewrite->rules = array_merge(array('download/([0-9]{1,})/?$' = 'index.php?dl_id=$matches[1]'), $wp_rewrite->rules);
}
Thread Starter
zoom4
(@zoom4)
GamerZ what version of WP are you using?
Your code doesn’t seem to work on 2.3
WP 2.3, you need to regenerate permalink again
Thread Starter
zoom4
(@zoom4)
OK thanks. I regenerated it, and now your example seems to work, so when I go to http://www.example.com/download/22/ I don’t get the 404 anymore.
Now what I need is to use that dl_id variable, but of course now it is not in the $_GET array. I am guessing it should be somewhere with $wp_query but I didn’t figure out exactly where yet.
So what would be the equivalent of
echo $_GET[‘dl_id’] ?
Thread Starter
zoom4
(@zoom4)
Finally I got it!
What would have been one line code if the rewrite rules were placed in .htaccess now it needs 3 functions!
Zoom4, would you mind sharing what you did and the scenario of how it worked? I’ve been trying to do something similar and running into deadends.
My details can be found at http://wordpress.org/support/topic/143258?replies=6
I currently have /page1/page2 where page1 is the parent. I could easily change it to /page1/ and page2/ if that makes it easier.
add_filter('query_vars', 'download_query_vars');
function download_query_vars($public_query_vars) {
$public_query_vars[] = "dl_id";
return $public_query_vars;
}
To get dl_id:
$dl_uid = intval(get_query_var('dl_id'));
Thread Starter
zoom4
(@zoom4)
Hello mjulson,
Your situation is a bit different than mine but the answers are in this doccument:
http://codex.wordpress.org/Custom_Queries
You will need to write a plugin that should contain 3 things:
1) The query variables that you expect. getCat in your case. Follow the example that GamerZ gave above, just replace “dl_id” with “getCat”
2) A function that will flush the rewrite rules, copy paste the code bellow, if you want you can rename the function name but it doesn’t really matter:
add_action(‘init’, ‘geotags_flush_rewrite_rules’);
function geotags_flush_rewrite_rules()
{
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
3) A function to add your own rules:
add_action(‘generate_rewrite_rules’, ‘geotags_add_rewrite_rules’);
function geotags_add_rewrite_rules( $wp_rewrite )
{
$new_rules = array(
‘geostate/(.+)’ => ‘index.php?geostate=’ .
$wp_rewrite->preg_index(1) );
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
Obviously you need to change the $new_rules line with your own rules.
Due to canonical URL’s WP_Rewrite is really inconsistent.
Canonical sucks.
Try this thread, rewrite is still pretty scary but for the original poster’s problem I think this might work:
http://wordpress.org/support/topic/174334