Make WordPress Core

Opened 16 months ago

Last modified 16 months ago

#57858 new defect (bug)

If permalink structure is set to /%category%/%postname% , WordPress will match a /0/ path as a category archive

Reported by: krdevio's profile krdevio Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.1.1
Component: Rewrite Rules Keywords: has-testing-info needs-testing needs-patch
Focuses: Cc:

Description

Issue:

When the post permalink structure (Settings > Permalinks > Permalink Structure > Custom Structure ) is set to /%category%/%postname% , any path containing /0/ will be matched as a category archive page.

eg.
example.com/wp-content/0/ will not return a 404, and resolve to category archive template.
example.com/wp-includes/0/ will not return a 404 and resolve to category archive template.
example.com/wp-admin/0/ will not return a 404 and resolve to category archive template.
example.com/some-post-name/0/ will resolve to some-post-name
example.com/0/ will properly resolve to the site_url, but still wont 404

Setting the permalink to anything but that, eg. /%author_name%/%postname% it will properly 404.

I'm guessing somewhere in the permalink structure, 0 is seen as a valid category and not empty/null.

Steps to reproduce:

  1. Spin up a fresh WordPress
  2. Go to Settings > Permalinks > Permalink Structure > Custom Structure
  3. Set the Custom Structure to: /%category%/%postname%
  4. Visit one of the example URLs above.

We found this issue as we noticed Google was indexing a page like example.com/wp-content/uploads/2011/0/

Attachments (2)

Screenshot 2023-03-11 at 1.00.01 PM.png (260.6 KB) - added by mujuonly 16 months ago.
Permalink settings
Screenshot 2023-03-11 at 12.59.44 PM.png (498.8 KB) - added by mujuonly 16 months ago.
Category archive

Download all attachments as: .zip

Change History (9)

#1 @costdev
16 months ago

  • Keywords has-testing-info needs-testing added

Hi @krdevio, welcome to Trac and thanks for opening this ticket.

I'm just adding some keywords to help get this ticket some more attention. 🙂

Related/Semi-duplicate:

  • #37812 - For the same setup, reports 404 (opposite of this ticket), with possible changes resulting in this ticket's issue, but with inconsistent reports from commenters.

#2 follow-up: @kalpeshh
16 months ago

I am getting proper 404 for all the cases you mentioned except below,

example.com/0/ will properly resolve to the home page and does not give 404

/0/some-post-name will properly resolve to some-post-name page regardless of in which category it belongs

#3 in reply to: ↑ 2 @krdevio
16 months ago

Replying to kalpeshh:

I am getting proper 404 for all the cases you mentioned except below,

example.com/0/ will properly resolve to the home page and does not give 404

/0/some-post-name will properly resolve to some-post-name page regardless of in which category it belongs

I just retested, you know what you are correct. My apologies My permalink settings were not exactly
/%category%/%postname%, and testing that it was fine as you said.

With that said it might still be a bug: The exact permalink setting I had was /%category%/%postname%.html (.html at the end). I guess adding the .html at the end causes /0/ to match as mentioned initially.

#4 @mujuonly
16 months ago

Welcome to core track, thanks for creating ticket

I have tried to reproduce this issue and you are right it does resolve to category archive

The link example.com/wp-content/0/ will not return a 404, and resolve to category archive template.

Test Report

Env

WordPress 6.1.1
Chrome Version 110.0.5481.177 (Official Build) (arm64)
MacOS Monterey
Theme: Twenty Twenty Three

Steps to test

  1. The exact permalink setting I had was /%category%/%postname%.html
Last edited 16 months ago by mujuonly (previous) (diff)

@mujuonly
16 months ago

Permalink settings

#5 @sarunraj
16 months ago

Welcome to core track, thanks for creating ticket

I have tried to reproduce this issue and you are right it does resolve to category archive when you adding permalink /%category%/%postname%.html . if you add permalink /%category%/%postname%/html like this it will redirect into 404 page https://prnt.sc/x_kBuK_lVqFK.

Env

WordPress 6.1.1
Chrome 110.0.5481.177
MacBook Air M1
Theme: Twenty Twenty Three
Gutenberg Editor

This ticket was mentioned in Slack in #core-test by juhise. View the logs.


16 months ago

#7 @kalpeshh
16 months ago

  • Keywords needs-patch added

The issue is happening because of REGEX match if you have .htm or anything starting with dot (.) at the end of permalink.

Seems like a valid issue.

Note: See TracTickets for help on using tickets.