[wp-hackers] WP_Rewrite query
Andy Skelton
skeltoac at gmail.com
Sat Feb 4 22:39:59 GMT 2006
On 2/4/06, Rob <powzor at gmail.com> wrote:
> I was under the impression that WP_Rewrite was the only way to modify
> the rewrite rules in .htaccess, which I need to do if I want to have
> /library/ instead of
> /wp-content/plugins/my-plugin/my-plugin.php?library=true which is vastly
> more ugly.
There are a few different ways to inject rules into .htaccess only,
skipping wp_rewrite->rules. If you know your code only needs to work
on Apache with mod_rewrite, no problem. However for portability you
must use wp_rewrite instead.
When I say wp_rewrite I'm referring to the rewriting engine built into
the WP_Rewrite and WP classes. It works whether or not mod_rewrite is
available.
The function $wp->parse_request() does the work of finding the rule
that matches the request. It never populates any member of the $_GET
array. Instead it populates the array $wp->query_vars.
It doesn't just grab every query var from the rewritten query
willy-nilly. It only sets those vars named in $wp->public_query_vars.
If you want to add a varname to the list, use the 'query_vars' filter.
function nr_query_vars($array) {
$array[]='library';
return $array;
}
add_filter('query_vars', 'nr_query_vars');
Andy
More information about the wp-hackers
mailing list