WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.