#2123 closed defect (bug) (fixed)
Custom 404 stops working when using /%category%/%postname%/ as permalink structure
Reported by: | Huvet | Owned by: | 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)
Change History (13)
#4
@
19 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
@
19 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
#7
@
19 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.
#8
@
19 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?
(In [3338]) Don't get children for cat 0. fixes #2123