Make WordPress Core

Opened 11 years ago

Last modified 3 weeks ago

#28156 reopened defect (bug)

In date-containing permalink structures, /dddd/dd/comment-page-d/ urls don't work

Reported by: mboynes's profile mboynes Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.9
Component: Permalinks Keywords: needs-patch dev-feedback needs-unit-tests
Focuses: Cc:

Description

I was in the process of writing a plugin to allow people to test their rewrite rules as they develop a site, and when I setup examples of core rewrite rules, one of them was failing.

If you set your permalink structure to one containing dates, e.g. "Day and Name", one of the generated rewrite rules for posts is:

'([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)(/[0-9]+)?/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&name=$matches[4]&page=$matches[5]'

And later on, another rule is:

'([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/comment-page-([0-9]{1,})/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&cpage=$matches[4]'

The URI /2014/5/6/comment-page-2/ would end up matching the earlier rule, looking for a post named "comment-page-2" published on 2014-05-06, instead of looking for comment page 2 in the... I actually don't even know what the comment-page URLs do. For me, the ones that work just redirect to the date archive.

I'm happy to patch this, but would like to hear from someone else on what exactly should be done done. Do the comment-page-n rules do anything? Can they just be removed?

Attachments (2)

Screenshot 2025-06-26 at 15.53.28.png (61.4 KB) - added by callumbw95 3 weeks ago.
My comments config
Screenshot 2025-06-26 at 16.00.10.png (127.5 KB) - added by callumbw95 3 weeks ago.
My Permalink config

Download all attachments as: .zip

Change History (8)

#1 @Milmor
10 years ago

  • Keywords needs-patch dev-feedback needs-testing added

Can confirm that.

  • Post url: /2015/02/04/comment-page-2/
  • Comments paging active (3-per-page, 7 comments made)

The post url doesn't give me 404, but there are definetely some problems.

Eg.

  • instead of taking me to /2015/02/04/comment-page-2/comment-page-1 i go to 2015/02/04/comment-page-1 (404)
  • instead of taking me to /2015/02/04/comment-page-2/comment-page-3 i go to /nightly/2015/02/04/comment-page-3 (404)

#2 @valendesigns
10 years ago

  • Keywords needs-unit-tests added; needs-testing removed

I wasn't aware that you could view comments outside of their posts in an date based archive format.

#3 @callumbw95
4 weeks ago

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

Hi All,
I have taken a look at this in the latest release, and it looks like the comments page rewrite rules no longer exist within WordPress. As of such I don't believe this is an issue in the current state of the codebase.

#4 @mboynes
4 weeks ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

@callumbw95 I just checked on 6.8.1 and the comment page rules do still exist and the issue also persists as originally described. Perhaps you didn't follow the step, If you set your permalink structure to one containing dates, e.g. "Day and Name"?

#5 @callumbw95
3 weeks ago

Hey @mboynes,
Yes you are correct, my mistake there, I think I jumped the gun there a bit, as I can see the rewrite rule in the code now too. I have set up a fresh test site with the correct Day and Name permalink structure, and I have created a test post with multiple comments that go across multiple pages. However I am not seeing the issues you are having here with url's not working?
I have the following url's and they are working as intended:

  • /2025/06/26/28156-test-page/comment-page-1/#comments
  • /2025/06/26/28156-test-page/comment-page-2/#comments
  • /2025/06/26/28156-test-page/comment-page-3/#comments

Environment

  • WordPress: 6.9-alpha-60093-src
  • PHP: 8.4.7
  • Server: nginx/1.27.5
  • Database: mysqli (Server: 8.0.40 / Client: mysqlnd 8.4.7)
  • Browser: Chrome 137.0.0.0
  • OS: macOS
  • Theme: Twenty Twenty Five 1.2
  • MU Plugins: None activated
  • Plugins:
    • Test Reports 1.2.0

@callumbw95
3 weeks ago

My comments config

@callumbw95
3 weeks ago

My Permalink config

#6 @mboynes
3 weeks ago

Hey @callumbw95, the ticket is a bit confusing. I'd make it more clear, but I don't actually understand the intended functionality. The URLs that don't work aren't single-post comment page urls (as you were looking at), they're (I guess?) date archive comment page URLs. An example URL is /2025/06/26/comment-page-2/.

The specific rule is:

([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/comment-page-([0-9]{1,})/?$
=> index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&cpage=$matches[4]

There are other, similar rules, that don't 404 but don't seem to show anything comments-related:

([0-9]{4})/([0-9]{1,2})/comment-page-([0-9]{1,})/?$
=> index.php?year=$matches[1]&monthnum=$matches[2]&cpage=$matches[3]

([0-9]{4})/comment-page-([0-9]{1,})/?$
=> index.php?year=$matches[1]&cpage=$matches[2]

My best guess is that the real bug here is that these urls are invalid and are added inadvertently, probably here. If that's the case, then the fix for this ticket would be to move this block outside of the directories loop and only add it once to the single post URL. But, perhaps there is a feature of WordPress that I'm not aware of! Even after working with it for almost 20 years, it still surprises me from time to time :-).

Note: See TracTickets for help on using tickets.