Make WordPress Core

Opened 18 years ago

Closed 18 years ago

Last modified 17 years ago

#2123 closed defect (bug) (fixed)

Custom 404 stops working when using /%category%/%postname%/ as permalink structure

Reported by: huvet's profile Huvet Owned by: ryan's profile ryan
Milestone: Priority: normal
Severity: normal Version: 2.0
Component: General Keywords: 404 category bg|has-patch bg|dev-feedback
Focuses: Cc:

Description

When setting the permalink structure to /%category%/%postname%/ my custom 404 stops working and takes me to the archive page instead.

I talked to the very helpful ringmaster in the IRC-channel and he concluded:

<ringmaster> Huvet, it's doing that because it's matching the invalid name against the category-based permalink structure and failing to find a match. But wp_query is still reporting is_category for the query, so it forwards you to that template. Nice.

Attachments (1)

404 non existant posts, authors and cats.diff (1.8 KB) - added by majelbstoat 18 years ago.
404 when an invalid postname / category / authorname is supplied

Download all attachments as: .zip

Change History (13)

#1 @masquerade
18 years ago

  • Milestone set to 2.0

#2 @ryan
18 years ago

  • Owner changed from anonymous to ryan

#3 @ryan
18 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [3338]) Don't get children for cat 0. fixes #2123

#4 @Huvet
18 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

I still get a blank page instead of my custom 404. An example is this url: http://friendlybit.com/url_that_doesn't_exist

I'm using the permalink structure: /%category%/%postname%/ and category base /articles if that helps. Anything else you need?

#5 @Huvet
18 years ago

It seems that because of this bug I can't get verified on Google Sitemaps. They check a random non working url to see if it returns a correct 404. Mine return 200 OK because of this bug so I can't get verified. Details here: https://www.google.com/webmasters/sitemaps/docs/en/verify.html#verificationfileconfigerror

#6 @skeltoac
18 years ago

  • Milestone changed from 2.0 to 2.0.1

#7 @majelbstoat
18 years ago

  • Keywords bg|has-patch bg|dev-feedback added

This can't really be avoided at the rewrite stage because the (.+?) clause that replaces /%category%/ will catch everything. The same thing will probably happen for permalink structures that start with /%postname%/ or /%author%/ . One solution is to insert a check in parse_query() to see if the supplied variable is an existant cat/author/postname and set a 404 from there if it isn't.

The supplied patch does this, at a cost of one extra db access per test for category or author or postname-specified singles. Of these, the biggest hit will be the postname db access, used in a more 'traditional' structure of /%year%/%monthnum%/%day%/%postname%/ . However, with caching, this may be an acceptable tradeoff, resulting in an extra access only for a non-existant request (the thinking being that requests for pages that exist will already be cached).

This works for me in latest SVN.

@majelbstoat
18 years ago

404 when an invalid postname / category / authorname is supplied

#8 @majelbstoat
18 years ago

In fact, for the permalink structure described, this will require 2 db accesses. A better solution, may be to skip further db accesses if the first one returns a 404. Thoughts?

#9 @ryan
18 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [3484]) 404 if category not found. fixes #2123

#10 @majelbstoat
18 years ago

Ha! Always with the easy solutions! Nice.

#11 @Huvet
18 years ago

Thanks! It works fine.

#12 @(none)
17 years ago

  • Milestone 2.0.1 deleted

Milestone 2.0.1 deleted

Note: See TracTickets for help on using tickets.