WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 3 months ago

Last modified 3 months ago

#14036 closed defect (bug) (worksforme)

Post 404 errors due to a base post's name matching the Permalink option "category base"

Reported by: sniper231 Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Permalinks Keywords: has-patch
Focuses: Cc:

Description

When the "category base" option under Settings>Permalinks is set as a value, one can still create a post with the same value used as the new post's name and thus its permalink path. Thus, when a user tries to navigate to the post via its permalink, Wordpress thinks the user wants to access a category and gives a 404 error.

Here's an example.

Say I set my category base in Settings>Permalinks to "general." All my categories are at mysite.com/general/... Now say I make a regular post and name it "General." Wordpress automatically assigns it the permalink "mysite.com/general". So, on my menus that list this post, this will be the link. However, when a user visits this link, Wordpress is set to recognize /general/ as the category base and it gives the user a 404 error. All subposts under "General" also have a permalink that begins with mysite.com/general/ and thus are seen as categories by apache mod_rewrite and become 404 as well.

Solution: users should not be able to have base pages whose names (and thus permalinks) are exact matches to the Settings>Permalinks>Category base value.

Attachments (1)

14036.diff (1.4 KB) - added by solarissmoke 3 years ago.
For top level pages, check slug against category and tag bases

Download all attachments as: .zip

Change History (6)

comment:1 gazouteast4 years ago

Interesting - wonder if this also has bearing on the problems with multisite sub-blogs returning 404s on posts and pages (and archives, tag pages etc) due to the use of " files/ " in the default configuration and rewrite rules?

comment:2 nacin3 years ago

  • Milestone changed from Awaiting Review to Future Release

Correct me if I'm wrong, but:

/general as the category base, then the page /general will work. On the other hand, the page /general/sub will not work, as WP will think it is a category called 'sub'.

Something should be prevented from clashing. My guess, is unique_post_slug should make sure it can't conflict with the category base, for sub pages.

solarissmoke3 years ago

For top level pages, check slug against category and tag bases

comment:3 solarissmoke3 years ago

  • Keywords has-patch dev-feedback added; permalink 404 page name removed

comment:4 johnbillion3 months ago

  • Milestone Future Release deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Tested in 3.8.1, no longer appears to be an issue. Tested in single site and multisite, and with posts and pages. Post, page and category permalinks all work as expected.

comment:5 SergeyBiryukov3 months ago

  • Keywords dev-feedback removed

Could not reproduce neither in 3.0 (when the ticket was created) nor in current trunk.

My steps:

  1. Set permalink structure to /%postname%/.
  2. Changed category base to general.
  3. Created a post named "General".
  4. Successfully opened the post on the front-end.
  5. Repeated steps 3 and 4 with a page instead of a post.

I can only reproduce the 404 error if there's a deleted page with the same name as the post. See #21970 for that.

Note: See TracTickets for help on using tickets.