1

I have tried to rewrite the url from http://example.com/club/?state=AL

to http://example.com/club/AL

Added query vars and rewrite url in functions.php

add_filter('query_vars', 'my_query_vars', 10, 1);

function my_query_vars($vars) {
    $vars[] = 'club'; 
    return $vars;
}


function custom_rewrite_basic() 
{
    add_rewrite_tag("%club%", "([a-z0-9\-_]+)");
       add_rewrite_rule('^club/([a-z0-9\-_]+)/?$', 'index.php?pagename=club&State=$matches[1]', 'top');

}
add_action('init', 'custom_rewrite_basic');
1
  • Your query var that you added is named club, not State, you would also need to modify your page to read in the value using get_query_var not $_GET and your add_rewrite_tag call is unnecessary. Also did you re-save your permalinks after making these changes, and have you tested your URL using the rewrite rule analyser plugin? Did you change your links to point to the new pretty permalinks instead? ( WP won't do that for you )
    – Tom J Nowell
    Feb 11 at 20:56

1 Answer 1

0

You can create an Apache .htaccess internal rewrite

RewriteEngine on
RewriteCond %{QUERY_STRING} ^state\=AL$
RewriteRule ^club/$ /club/AL? [L]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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