Ticket #5305 (new defect (bug))
permalinks broken when article name is numeric
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Permalinks | Version: | 2.3.1 |
| Severity: | major | Keywords: | needs-patch |
| Cc: | lkraav |
Description
if you create numeric-only post name, the generated slug is this number - this conflicts with article ID, so it returns different article or 404 page, never the article. It can be then solved by generating manual slug with some char in it, but i think it would be better to include some char in that case, e.g. underscore, like _123
Also if someone will try to solve this, it would be nice to solve other problem - if post slug is begining with the slug of the category, than the category page returns that post, not the category
Change History
I don't think he's using permalinks. I think he's saying, like if his post slug is 123 and his title is 123, it breaks. It looks like 2.4 trunk doesn't break like that though. Unless it is a specific permalink structure.
My structure is /archief/%postname%/, and I see the same problem. I've simply re-slugged the offending posts to the number in words, so 30 would become "thirty" (or in my case, "dertig", as I'm Dutch).
I didn't have this problem when my structure was /archief/year/month/day/postname/ though.
Actually, I am able to verify that this does happen. If you have a custom permalink, where you have something like /archives/%postname%/ or /archives/post/%postname%/ and you publish a post with a numeric title such as 2008, when you click to view the post, you get a 404 error. In all my testing, this only occurs with this type of a permalink where you have a static word followed by a forward slash and then the dynamic postname.
If you try /archive/%author%/%postname/ or put any of the other dynamic options between the static word and the dynamic postname, the link will work fine.
I verified this in 2.3.1 and in 2.4 trunk.
Also, if you have a custom permalink that is just /%postname%/ you get a 404 error on a post with a numeric title.
As for the other problem that was mentioned concerning if a post slug is beginning with the slug of the category, than the category page returns that post, not the category. I have been unable to recreate it.
Just a note, Ryan in comment 25 on ticket #3614 ( http://trac.wordpress.org/ticket/3614#comment:25) explains why the 404 errors occur with permalinks like those that I tried (I don't personally use them myself) or that others use. I have yet to test the fix that they have come up with on that ticket to see if it solves the problem here(although, it appears as though you would still need to modify your permalinks structure to not be like those above). When I get a chance I'll test this ticket based on ticket #3614.
I've just a had a similar ticket closed as a duplicate, although I'm not 100% sure from the comments here that people have grasped what the problem is.
If you need examples, check the info on http://trac.wordpress.org/ticket/6997
To summarise, I create a page (lets call it "a"). The slug is also "a". I then create another page, give it a slug of "2008" and set "a" to be its parent. When I try to navigate to /a/2008/, it simply shows me the content of "a", rather than "2008". If I add anything else onto the end (ie a/2008/a/) it redirects me to a post written in 2008.
I just seems to be the case that as soon as it sees 2008, it tries to guess what I want, rather than just checking to see if there is actually a page called 2008.
By the look of it, Its reconising the 2008 as a page value(ie. The 2008th page):
object(WP_Query)[3]
public 'query_vars' => &
array
'page' => string '/2008' (length=5)
'pagename' => string 'a' (length=1)
(Which in itself seems to be a bug that /2008 is reconised as the page number, it shouldnt have the slash in there)
The rule which is being matched is:
[(.+?)(/[0-9]+)?/?$] => index.php?pagename=$matches[1]&page=$matches[2]
I can see 2 ways to resolve it:
- Revert to the old method of actually having *every* page slug being checked for, which is slow, messy, and really isnt going to happen
- Limit pages to only have a certain ammount of pages (Why remove functionality?)
- Prefix extra pages with /page/
More on that last one: Most common permalink structures in WordPress allready use that method (.*/page/[0-9]+).
Changing the current permalink settings will break links on pages at present (ie. /a/2/ for page 2) in search results, But would allow for numeric page slugs on subpages.
comment:10
DD32 — 4 years ago
Also, For consistancy, Is there a reason thats using &page= instead of &paged= ?
I also had a ticket about this closed and I had no idea it existed already, sorry; as I had no such problems in any version prior to 2.5.1. I'm confused now. How come that the issue occurs in different versions of WP for each person?
comment:12
Viper007Bond — 4 years ago
See also: #7365
comment:13
Viper007Bond — 4 years ago
For anyone looking to do this meanwhile and is willing to give up the paging ability, here's a plugin I wrote:
<?php
/*
Plugin Name: Allow Numeric Stubs
Description: Allows children Pages to have a stub that is only a number. Sacrifices the <code><!--nextpage--></code> ability in Pages.
Version: 2008.07.23
Author: Viper007Bond
Author URI: http://www.viper007bond.com/
*/
// Register plugin hooks
register_activation_hook( __FILE__, 'allow_numeric_stubs_activate' );
add_filter( 'page_rewrite_rules', 'allow_numeric_stubs' );
// Force a flush of the rewrite rules when this plugin is activated
function allow_numeric_stubs_activate() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
// Remove the offending rule and replace it with something else
function allow_numeric_stubs( $rules ) {
unset( $rules['(.+?)(/[0-9]+)?/?$'] );
$rules['(.+?)?/?$'] = 'index.php?pagename=$matches[1]';
return $rules;
}
?>
comment:14
bitethemailman — 4 years ago
This never happened to me in 2.3.2, but happens in 2.5. I'm having the same problem described by chrismou in comment 8. Duplicated in #7444.
comment:15
Viper007Bond — 4 years ago
Above code released as a plugin BTW: http://wordpress.org/extend/plugins/allow-numeric-stubs/
comment:16
mrmist — 3 years ago
Also ref #7355
- Owner changed from anonymous to ryan
- Component changed from General to Permalinks
comment:20
janeforshort — 2 years ago
- Milestone changed from 2.9 to Future Release
Punting due to schedule.
comment:21
Viper007Bond — 9 months ago
See also this dupe ticket with some good discussion on it: #14238
comment:22
follow-up:
↓ 23
SergeyBiryukov — 7 months ago
Just stumbled upon this. Steps to reproduce:
- Create a post with slug 1.
- Set permalink structure to /%year%/%monthnum%/%postname%/.
- Then we have request: 2008/12/1
- Matched rule: year=2008&monthnum=12&day=1
Other permalink structures (Day and name, Numeric, even /%postname%/ mentioned above) work fine.
comment:23
in reply to:
↑ 22
;
follow-up:
↓ 24
Viper007Bond — 7 months ago
Replying to SergeyBiryukov:
- Create a post with slug 1.
I don't believe that's possible. WordPress will currently change that to 1-2 as far as I know.
comment:24
in reply to:
↑ 23
SergeyBiryukov — 7 months ago
Replying to Viper007Bond:
I don't believe that's possible. WordPress will currently change that to 1-2 as far as I know.
That's for pages. It's still possible to create a post with a numeric-only slug.
comment:25
SergeyBiryukov — 4 months ago
Duplicate: #19036

thomask, can you include your Permalink Structure? And provide specific examples? This could help duplicate the problem.