Make WordPress Core

Opened 17 years ago

Closed 15 years ago

Last modified 15 years ago

#6603 closed defect (bug) (fixed)

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

Reported by: robanna's profile robanna Owned by: ryan's profile ryan
Milestone: 2.8 Priority: high
Severity: major Version: 2.5
Component: Permalinks Keywords: has-patch tested commit
Focuses: 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 16 years ago.
possible solution
rewrite-new.patch (945 bytes) - added by emartin24 16 years ago.
new patch - moved code from init() into page_rewrite_rules() function
6603.diff (947 bytes) - added by Denis-de-Bernardy 15 years ago.
more general fix

Download all attachments as: .zip

Change History (35)

#1 @robanna
17 years ago

  • 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.

#2 @robanna
17 years ago

  • Milestone changed from 2.7 to 2.5.1

#3 @dhardy
17 years ago

  • 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.

#4 @ryan
17 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.

#5 @robanna
17 years ago

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

That looks like it'll fix it.
Thanks-

#6 @Viper007Bond
17 years ago

  • Resolution worksforme deleted
  • Status changed from closed to reopened

Not fixed, reopening.

#7 @Viper007Bond
17 years ago

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

#8 @ryan
17 years ago

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

#9 @dhardy
16 years ago

Has this been fixed in 2.6?

#10 @ryan
16 years ago

  • Milestone changed from 2.5.2 to 2.7

#11 @dhardy
16 years ago

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

#12 @mtekk
16 years ago

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.

#13 @creativeworldstudio
16 years ago

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.

#14 @markmathson
16 years ago

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.

#15 @ryan
16 years ago

  • Milestone changed from 2.7 to 2.8

#16 @robanna
16 years ago

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...

#17 @emartin24
16 years ago

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?

@emartin24
16 years ago

possible solution

#18 @emartin24
16 years ago

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?

#19 @emartin24
16 years ago

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

#20 @emartin24
16 years ago

  • Keywords has-patch needs-testing page added; "has-patch needs-testing" page" removed

#21 @emartin24
16 years ago

  • Keywords "static posts page removed

@emartin24
16 years ago

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

#22 @emartin24
16 years ago

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)

#23 @emartin24
16 years ago

  • Keywords 2nd-opinion dev-feedback added

@Denis-de-Bernardy
15 years ago

more general fix

#24 @Denis-de-Bernardy
15 years ago

  • 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.

#25 @Denis-de-Bernardy
15 years ago

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

patch still works, with a hunk.

#26 @Denis-de-Bernardy
15 years ago

  • Component changed from General to Permalinks

#27 @ryan
15 years ago

  • 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

#28 @ryan
15 years ago

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.

#29 @Denis-de-Bernardy
15 years ago

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...

#32 @ryan
15 years ago

Sounds good.

Note: See TracTickets for help on using tickets.