Make WordPress Core

Opened 11 years ago

Last modified 11 years ago

#3964 closed defect (bug)

Aggressive matching in rewrite.php leads to "nothing matches" errors with custom rewrite endpoints — at Version 5

Reported by: jhodgdon Owned by: westi
Milestone: 2.2 Priority: normal
Severity: normal Version: 2.1.2
Component: General Keywords: rewrite reporter-feedback has-patch 2nd-opinion
Focuses: Cc:

Description (last modified by westi)

In a plugin, I call add_rewrite_endpoint to add a custom endpoint to the rewrite rules, and then cause a refresh of the rules by calling $wp_rewrite->flush_rules(). I add a suffix endpoint called "foo" to the rewrite rules, for a variety of situations, including post permalinks (in my case, "foo" is actually a language choosing parameter).

My permalink structure is set to /%category%/%postname%/

So, it's working fine on a post, category, page, etc. -- my suffixes are recognized and I can set the language and then find the post. But when I go to the home page and add suffixes, to get a permalink like:


the query fails, because the above it matches the post-with-page-suffix rewrite rule:


and WordPress thinks it is the post in category "foo" with slug "param" (which doesn't exist).

It's also a problem on feeds, where


matches the same matching rule, and WordPress thinks it is the post in category "feed/foo", with slug "param". That .+ at the beginning of the rule is pretty permissive.

I do have a rule:


but it is farther down in the list than the rule above, and so the rule above takes precidence.

I am not sure how to fix this... any ideas? The API doesn't allow for upping the precedence of rules. For now I have just made my plugin use a GET instead of permalink endpoint for the blog's home page and for feeds, but it is rather annoying.

Change History (5)

#1 @jhodgdon
11 years ago

  • Component changed from Administration to General
  • Priority changed from low to normal
  • Version set to 2.1.2

Forgot to mention, tested in 2.1.1 release, as well as [5012].

#2 @jhodgdon
11 years ago

  • Keywords rewrite added

#3 @foolswisdom
11 years ago

  • Milestone changed from 2.3 to 2.2

#4 @westi
11 years ago

  • Owner changed from anonymous to westi
  • Status changed from new to assigned

Could you attach some example code and/or a print_r of the generated rules for me to review what you are trying to achieve.

Reading through the rewrite code the permalink rules should come last in the array and so the extra endpoints should be matched earlier (or so i thought).

#5 @westi
11 years ago

  • Description modified (diff)
Note: See TracTickets for help on using tickets.