[wp-trac] [WordPress Trac] #41211: When the /category/category-name portion is repeated in the URL, it serves content instead of 404
WordPress Trac
noreply at wordpress.org
Sun Dec 19 12:08:16 UTC 2021
#41211: When the /category/category-name portion is repeated in the URL, it serves
content instead of 404
---------------------------+------------------------------
Reporter: sjwright1986 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Rewrite Rules | Version: 4.8
Severity: normal | Resolution:
Keywords: needs-patch | Focuses:
---------------------------+------------------------------
Changes (by bradleyt):
* keywords: => needs-patch
Comment:
I can reproduce this. It's worth noting that this has SEO implications as
WordPress does not output canonical meta tags on categories by default
(`rel_canonical` only runs on singular posts and pages).
Digging deeper it seems that any hierarchical categories are affected
(including custom taxonomies registered with `register_taxonomy()`). Non-
heirachical taxonomies, such as tags, do not seem to be affected.
In `class-wp-query.php` I've found the following code:
{{{
if ( ! empty( $t->rewrite['hierarchical'] ) ) {
$q[ $t->query_var ] = wp_basename( $q[ $t->query_var ] );
}
}}}
I'm not 100% sure, but it looks like WordPress may be extracting the
taxonomy type from the URL, extracting the last URL section, and then
ignoring everything in between.
For pages, this situation is avoided by checking for `get_page_by_path` in
`parse_request` in `class-wp.php`. Heirachical taxonomies could be checked
in the same way. Alternatively, the `handle_404` method in `class-wp.php`
could be extended to check the URL sections match the found taxonomies
parent.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/41211#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list