0

I'm created URL rules for my theme but some rules not applied in the correct order..

For example:

(1) This rule (with only one taxonomy) works fine:

/from/(.+?)/?$ => 'index.php?post_type=custom&from=' . $wp_rewrite->preg_index(1)

(2) And this another rule, with two or more taxonomies, not working because, the first rule (1) apparently it has higher priority or the regular expression is not well built.

/from/(.+?)/to/(.+?)/?$ => 'index.php?post_type=custom&from=' . $wp_rewrite->preg_index(1) . '&to=' . $wp_rewrite->preg_index(2),

I used "monkeyman rewrite analyzer" plugin to check my rules and this screenshot shows that this URL: .../from/madrid/to/toledo return the first rule instead the second.

What's wrong??

enter image description here

1 Answer 1

1

I'd say either change the order, put (2) before (1), or be more specific with the rules.

E.g.

from/([a-zA-Z]*)/?
5
  • If I change the regular expression, I get this message: Regex is empty! @sdexp
    – user101825
    Commented Sep 15, 2016 at 11:22
  • There are different websites to check regex's. This is one but there are others: regex101.com
    – sdexp
    Commented Sep 15, 2016 at 11:27
  • I meant to say that with the period "." you're matching everything, so you need to be more specific because the period will match "/" too.
    – sdexp
    Commented Sep 15, 2016 at 11:28
  • You might need to escape the forward slash like this... 'from\/([a-z]*)\/?'
    – sdexp
    Commented Sep 15, 2016 at 11:35
  • I changed the order of rules and apparently works fine!
    – user101825
    Commented Sep 15, 2016 at 11:59

Your Answer

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