[wp-trac] [WordPress Trac] #48223: parse_request(): When request has multiple matching rewrite rules, and matched rule returns 404 - iterate to next rewrite rule
WordPress Trac
noreply at wordpress.org
Sun Dec 29 16:59:25 UTC 2019
#48223: parse_request(): When request has multiple matching rewrite rules, and
matched rule returns 404 - iterate to next rewrite rule
------------------------------------+------------------------------
Reporter: apedog | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Rewrite Rules | Version:
Severity: normal | Resolution:
Keywords: has-patch dev-feedback | Focuses:
------------------------------------+------------------------------
Changes (by apedog):
* keywords: => has-patch dev-feedback
Comment:
I've written a rough patch that attempts to fix this issue.
The following changes have been made to {{{class-wp.php}}}:
Added variable {{{$all_matched_rules}}} - array of all possible rewrite
rule matches. This is unused but persistent.
Added variable {{{$matched_rules}}} - array of matched rules to loop over.
Function {{{parse_request()}}} creates array of all possible rewrite rule
matches and pops first rule off {{{$this->matched_rules}}} array,
populating {{{$this->matched_rule}}}.
On filter {{{'pre_handle_404'}}} added a function
{{{maybe_try_another_matched_rule()}}} that tests if other possible
rewrite rules exist for this request. If so, function parses request and
queries posts again for next matched rule available. It does so
recursively until {{{$matched_rules}}} array is empty. In which case it
defaults to default 404 handling.
This patch is more of a proof-of-concept. And would obviously need some
iterations if accepted. The code is convoluted and is redundant in some
areas. This can be fixed, with zero damage to logic, by making some
additional changes to {{{parse_request()}}}.
@SergeyBiryukov @johnbillion
--
Ticket URL: <https://core.trac.wordpress.org/ticket/48223#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list