0

On a multisite installation, which is running the Polylang plugin, I want to add a custom rewrite rule.

Currently, my permalink structure is:

http://host.com/sitename/language/pagename

Now I want to add a querystring called country, as such:

http://host.com/sitename/country/language/pagename

I have tried the following, but to no avail:

function custom_rewrite_basic() {
  add_rewrite_tag('%country%', '([^&]+)');
  add_rewrite_rule('^([a-z]+)/?', 'index.php?country=$matches[1]', 'top');
}
add_action('init', 'custom_rewrite_basic');

Any thoughts?

-- EDIT

Getting closer, but still not there:

add_rewrite_tag('%country%', '([^&]+)');
add_rewrite_tag('%lang%', '([^&]+)');
add_rewrite_rule('^([^/]*)/([^/]*)/?','index.php?country=$matches[1]&lang=$matches[2]','top');

The problem here is that:

  • polylang recognized the country as the language, even though the query var "lang" is set correctly
  • WP thinks we are not on the home page anymore

1 Answer 1

0

Your rule do not match the structure of the url you want. The rule basically handles urls with only a country. What is the right rule? you will need to look at the kind of rules the plugin produces and mimic them.

1
  • I updated my rule...
    – pdme
    Commented Sep 8, 2015 at 8:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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