• ARZCDR

    (@arzcdr)


    Hello,

    I am trying to add a rewrite rule but it doesn’t seem to be working at all and I think maybe I am not doing it correctly for it to work with Polylang. Here is the setup:

    * I have a page at [language code]/stories/countries/ (‘stories’ is a parent page)

    * I want to make it so that [language code]/stories/countries/[country-name] goes to the [language code]/stories/countries/ page with [country-name] as a query var called c_attr (I’ve already set up ‘c_attr’ as a query var using add_rewrite_tag)

    In other words, the rewrite rule I am looking to use is (it’s a little more general because I have other pages that are siblings of ‘countries’ but they all behave similarly):

    stories/([^/]+)/([^/]+)/?$ => index.php?pagename=$matches[1]&p_attr=$matches[1]&c_attr=$matches[2]

    But this rule never seems to trigger and I suspect it is not playing nice with Polylang.

    I found something about pll_rewrite_rules in the documentation, but I am not sure if it is indeed what I need, and if it is, I am not exactly sure as to how to use that sample code.

    Thanks in advance for any help!

    https://www.ads-software.com/plugins/polylang/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Chouby

    (@chouby)

    Did you check that your rewrite rule works when Polylang is inactive?

    If yes, did you check something like (supposed that en, fr, de are your languages codes):

    (en|fr|de)/stories/([^/]+)/([^/]+)/?$ => index.php?pagename=$matches[1]&p_attr=$matches[1]&c_attr=$matches[2]

    if your country name corresponds to a single post

    (en|fr|de)/stories/([^/]+)/([^/]+)/?$ => index.php?pagename=$matches[2]&p_attr=$matches[2]&c_attr=$matches[3]&lang=$matches[1]

    if your country name corresponds to an archive of posts

    Hello Chouby,
    I’m stuck on a plugin development for a website that use Polylang…
    I need to add a custom rewrite_rule

    add_rewrite_rule( 'webservice/([a-zA-Z0-9_-]+)?$', 'index.php?webservice=1&service=$matches[1]', 'top' );

    but when I flush rules, all custom post types with polylang they break…
    If I deactivate Polylang all works great…

    any idea?

    thank you in advance…
    Moise

    Plugin Author Chouby

    (@chouby)

    Hi!

    I already did such things without any issue. How do flush rewrite rules?

    Hello,
    thank you for your answer…
    after a few hours of debugging I noticed that my rule is interpreted as a page (fisically does not exist on db) because I’m using a template_redirect action to emulate a new page with the webservice as output.

    I tried some new rules but no one works…

    an exemple of what I tried is:

    add_rewrite_rule( '(it|en)/webservice/([a-zA-Z0-9_-]+)$', 'index.php?lang=$matches[1]&webservice=1&service=$matches[2]', 'top' );
    
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Polylang and Rewrite Rules’ is closed to new replies.