WordPress.org

Make WordPress Core

Opened 21 months ago

Last modified 3 months ago

#37812 new defect (bug)

404 when using a numeric slug and /%category%/ base

Reported by: mikejolley Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Permalinks Keywords: needs-unit-tests needs-patch
Focuses: Cc:

Description

To reproduce:

  1. Create a top and sublevel category. Lets say Parent > Child
  2. In permalink settings, set custom permalink structure /%category%/%postname%/
  3. Create a post with slug 12345 and assign to category "child"
  4. View post.

There is a 404.

Tested in 4.6 only. No other plugins active.

Change History (4)

#1 @swissspidy
21 months ago

  • Keywords needs-unit-tests needs-patch added
  • Milestone changed from Awaiting Review to Future Release
  • Version 4.6 deleted

Confirmed, also on older installs.

With a non-numerical slug the matched query is category_name=parent%2Fchild&name=test&page=, whereas with a numerical slug it is category_name=parent&name=child&page=12345.

The rewrite rule for the /%category%/%postname%/ structure is (.+?)/([^/]+)(?:/([0-9]+))?/?$ (category_name=$matches[1]&name=$matches[2]&page=$matches[3]).

Looks like numerical slugs should be forbidden in that case and suffixed (e.g. 1234-2). @boonebgorges didn't you fix something similar recently? Can't find the ticket.

#2 @boonebgorges
21 months ago

#5305 addressed the issue where the permalink of a post could conflict with a date archive if the post had a numeric permalink. So it's similar to this issue, but not related to dates - it has to do with pagination. It's likely that we could institute a similar sort of suffixing to what we did in #5305.

#3 @jayhughes
13 months ago

@boonebgorges @swissspidy I have had this issue for a while, exactly as @mikejolley explained. While the pages no longer 404 for normal traffic, they do 404 for Facebook's crawler and for Pinterest's crawler. I'm not sure if the initial error was fixed in WP, but if it was, it seems the error might still exist outside of normal browser traffic.

Hope this is helpful.

#4 @andrewteg
3 months ago

@jayhughes are you saying normal browser traffic is working for you? I'm on 4.9.4 and seeing this bug on any post with a numeric slug inside a child (or grandchild) category. We are using /%category%/%postname%/ like @mikejolley

Thanks.

Note: See TracTickets for help on using tickets.