WordPress.org

Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#8642 closed defect (bug) (fixed)

Canonical redirect of feed URLs with suffixes is wrong

Reported by: jhodgdon Owned by: markjaquith
Milestone: 2.7.1 Priority: normal
Severity: normal Version: 2.7
Component: Canonical Keywords: redirect has-patch
Focuses: Cc:

Description

As of [10215] and the 2.7 release, if for some reason I have a URL like

(myblogurl)/feed/(suffix)

then the redirect in wp-includes/canonical.php function redirect_canonical() redirects this to

(myblogurl)/feed/(suffix)/feed/

and that URL 404s.

The reason this happens is that the redirect_canonical() function, when it is dealing with feed-related URLs:

  1. strips off /feed/ only from the end of the URL
  2. checks is_feed() (which returns true if /feed/ is in the URL anywhere)
  3. if is_feed() is true, it assumes /feed/ has been completely stripped from the URL (which it hasn't if the /feed/ is not at the end), and adds /feed/ to the end of the URL.

The patch I am about to add to this report additionally strips /feed/ off the middle of the URL, which at least makes the redirect work for me -- then it redirects to

(myblogurl)/(suffix)/feed/

which works just fine.

By the way, there are some other places in the WP code where this assumption has been made, that certain things are always coming in at the end of URLs and not in the middle -- I have run into this before in previous WP versions and gotten around it with annoying shenanigans in my plugin that adds suffixes to URLs (among other functionality). Some of these issues are elsewhere in that same canonical_redirect() function, and some are in the rewrite logic (especially the parts of both having to do with paging). So if you feel ambitious, you might want to search these out and fix them. If not, I'd appreciate it if you could at least put this patch into the 2.7.1 release.

Attachments (2)

canonical.diff (783 bytes) - added by jhodgdon 10 years ago.
Patch to fix this bug by stripping /feed/ out of the middle of URLs in canonical redirect code
8642.002.diff (1.1 KB) - added by markjaquith 10 years ago.

Download all attachments as: .zip

Change History (8)

@jhodgdon
10 years ago

Patch to fix this bug by stripping /feed/ out of the middle of URLs in canonical redirect code

#1 @ryan
10 years ago

  • Component changed from General to Canonical
  • Owner changed from anonymous to markjaquith

#2 @markjaquith
10 years ago

8642.002.diff does the same, but within the existing regex. Does that fix it, Jennifer?

#3 @jhodgdon
10 years ago

I didn't know you could put a $ as a conditional inside a regex like that, cool! But I guess it is just a special matching character, after all. Duh.

I'll test this out shortly.

#4 @jhodgdon
10 years ago

In 2.8-bleeding [10398], your patch works fine.

It also works against 2.7.

#5 @markjaquith
10 years ago

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

(In [10505]) Strip /feed/ endings even if they are not at the very end, in canonical. props jhodgdon. fixes #8642 for trunk

#6 @markjaquith
10 years ago

(In [10506]) Strip /feed/ endings even if they are not at the very end, in canonical. props jhodgdon. fixes #8642 for 2.7

Note: See TracTickets for help on using tickets.