I am looking for some clarity on what add_rewrite_rules
does.
If I type in, or submit variables from a form, is it supposed to change the query variables to the pretty url?
Currently when I type in the pretty url, the page acts how I want. When I submit a form which redirects to a page with the query variables in the url, it also works fine. But I had thought that if I had typed in a url with the query variables, it would switch to the pretty url. It does not do that. Should it? Am I doing this wrong?
function add_query_vars($aVars) {
$aVars[] .= 'var_state';
$aVars[] .= 'var_clubs';
}
add_filter('query_vars', 'add_query_vars');
function add_rewrite_rules($aRules) {
$aNewRules = array(
'rv-clubs/([^/]+)/([^/]+)/?$' => 'index.php?pagename=rv-clubs&var_state=$matches[1]&var_clubs=$matches[2]'
);
$aRules = $aNewRules + $aRules;
return $aRules;
}
add_filter('rewrite_rules_array', 'add_rewrite_rules');
Any help would be appreciated.
You can see in this answer how
add_rewrite_rules
is being used, I don’t think it applies to your case at all.What you need to do is to redirect urls generated from the search from (I’m assuming something like
site.com/?s=term
) to a pretty URL. This article do it http://www.wptavern.com/how-to-make-the-wordpress-search-url-pretty