Opened 5 years ago

Closed 4 years ago

Last modified 4 years ago

#6603 closed defect (bug) (fixed)

bad next_posts_link when using a Static Front Page and custom permalink structure.

Reported by: robanna Owned by: ryan
Priority: high Milestone: 2.8
Component: Permalinks Version: 2.5
Severity: major Keywords: has-patch tested commit
Cc:

Description

I'm using the following link structure:

Front page displays
A static page (select below)

  • Front page: Home (www.apexprd.org)
  • Posts page: News and Events (www.apexprd.org/news-and-events)
  • Permalinks: /news-and-events/%postname%

In 2.3 this worked fine, I would get post pages under www/apexprd.org/news-and-events/page/2.

In 2.5, posts show up as www.apexprd.org/page/2 and not /news-and-events/page/2 as it should. The link for next_posts_link shows as /news-and-events/page/2 but when you click on it, it returns a 404 error.

If I change the permalink to anything but /news-and-events/ then it goes to the correct page

Example: permalink structure is /news-and-events/%postname%
click on next_posts_link and you get a 404 error. everything else works as it should

Change the permalink structure is /news-and-event/%postname% (remove the 's' on events)
click on next_posts_link and it goes to /news-and-events/page/2/ just fine but all of the post links look like /news-and-event/post-name

Could it be something in the rewrite.php file?

Attachments (3)

rewrite.patch (1.0 KB) - added by emartin24 4 years ago.
possible solution
rewrite-new.patch (945 bytes) - added by emartin24 4 years ago.
new patch - moved code from init() into page_rewrite_rules() function
6603.diff (947 bytes) - added by Denis-de-Bernardy 4 years ago.
more general fix

Download all attachments as: .zip

Change History (35)

  • Summary changed from bad next_posts_link when using a Static Front Page. to bad next_posts_link when using a Static Front Page and custom permalink structure.
  • Milestone changed from 2.7 to 2.5.1
  • Priority changed from normal to high
  • Severity changed from normal to major

I am having the same problem. I would like to ask that the priority be increased on this as it will cause problems for numerous users and ultimately make many current sites malfunction.

comment:4   ryan5 years ago

Look at line 1002 of wp-includes/rewrite.php.

http://trac.wordpress.org/browser/tags/2.5/wp-includes/rewrite.php#L1002

Change that line from this:

$this->use_verbose_page_rules = false;

to this:

$this->use_verbose_page_rules = true;

Change false to true. With that done, go to the Settings->Permalinks page and click "Save Changes". Does that help? If so I can create a plugin that does that for you. I'll try to fix this properly for 2.5.1, but given that this setup works more by accident than design a proper fix might be difficult.

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

That looks like it'll fix it.
Thanks-

  • Resolution worksforme deleted
  • Status changed from closed to reopened

Not fixed, reopening.

(Not that I'm having this problem, just saying editing core != fixed.)

comment:8   ryan5 years ago

  • Owner changed from anonymous to ryan
  • Status changed from reopened to new

Has this been fixed in 2.6?

  • Milestone changed from 2.5.2 to 2.7

Thanks I will check back when 2.7 is out ;-)

Closed #7200 as a duplicate of this.

Also in case you did not notice, it is not the s that is causing it. What happens is if that first part of the permalink is the same as your posts page the links look correct but lead to 404s or a post that WordPress thinks redirecting you to is the most proper thing.

Hi Ryan - I've documented some of this issue in this thread: http://wordpress.org/support/topic/159406#post-802603 - Just posting as it might help with clues to resolving this issue.

I was experiencing this issue, am using 2.6, and just fixed it using Ryan's recommended method described above.

So far I have not seen any negative side-effects.

  • Milestone changed from 2.7 to 2.8

This is still an issue in 2.7. I see that it's been changed from 2.7 to 2.8. I'm just saying...

ryan - I'm now facing this issue as well. You mentioned in your previous comment:

but given that this setup works more by accident than design a proper fix might be difficult.

I'm curious what you mean by "this setup works more by accident"? I have WordPress installed in /wordpress, a static home (/) and posts (/blog) page and configured permalinks to use the /blog prefix. This seems like it would be a common configuration.

I was going to try and look into the issue (past the solution you provided), but was curious what about this "configuration" that makes it hard to fix?

possible solution

Attached a patch with a possible solution. It fixes my issue, but I'm not sure what possible side-effects it might have.

Anyone else willing to apply and test?

  • Keywords "has-patch needs-testing" permalink "static posts page" rewrite added
  • Keywords has-patch needs-testing page added; "has-patch needs-testing" page" removed
  • Keywords "static posts page removed

new patch - moved code from init() into page_rewrite_rules() function

Added a new patch that moves the check into the page_rewrite_rules() function. I had it in the init() function until I realized that it was being called on every request instead of just the necessary ones.

I did find one side-effect...if you make the change to use a static posts page and use a new permalink (adding /blog for example) to an existing site, by default, the old post url's will not work - they will just return a 404.

For example:
mysite.com/my-post (before - will no longer work after change)
mysite.com/blog/my-post (after)

  • Keywords 2nd-opinion dev-feedback added

more general fix

  • Keywords dev-feedback permalink rewrite removed

I uploaded a new patch for this one. It changes the use_verbose_page_rules check, in such a way that constant strings at the beginning of the structure are ignored.

  • Keywords tested commit added; 2nd-opinion needs-testing removed

patch still works, with a hunk.

  • Component changed from General to Permalinks
  • Resolution set to fixed
  • Status changed from new to closed

(In [11335]) Better verbose page rule detection to support showing posts on a page with a custom permastruct. Props Denis-de-Bernardy. fixes #6603

That patch might be too aggressive in turning on verbose rules. /archives/%postname% probably shouldn't invoke verbose rules if archives is not a page. Hmmmm.

agreed, but it's meant to fix this, above all:

In 2.5, posts show up as www.apexprd.org/page/2 and not /news-and-events/page/2 as it should.

we'll work out how to dump these verbose rules after. it's not a very common use-case anyway...

see #9825 as well

Sounds good.

Note: See TracTickets for help on using tickets.