Make WordPress Core

Opened 13 years ago

Last modified 6 years ago

#17653 accepted enhancement

Canonical Redirect when space(s) are used instead of hyphens when requesting a page

Reported by: jamescollins's profile jamescollins Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: Future Release Priority: normal
Severity: normal Version: 3.0
Component: Canonical Keywords: has-unit-tests needs-patch
Focuses: Cc:


Create a page with a slug that contains a hyphen (eg. /page-name/).

If you then visit /page name/ (ie. use a space instead of a hyphen), WordPress currently manages to locate and display the page-name page. This could cause duplicate content issues.

The same issue occurs if multiple spaces are used instead of a hyphen.

As an example, this is the original page:

This page is accessible via:

and so on.

WordPress should either output a 404 error, or redirect to /page-name/.

Tested using the latest 3.2 trunk (r18110).

Attachments (3)

12456.diff (1.2 KB) - added by wonderboymusic 11 years ago.
17653-tests.patch (1.7 KB) - added by jared_smith 10 years ago.
Unit tests
17653-tests.2.patch (851 bytes) - added by boonebgorges 10 years ago.
Removing from trunk as per #30284

Download all attachments as: .zip

Change History (17)

#1 @dd32
13 years ago

  • Owner set to dd32
  • Status changed from new to accepted

Said I'd have a look at this.

I was genuinely surprised that WordPress was locating the correct page to start with, Even more surprised that canonical doesn't already catch it.

#2 follow-up: @dd32
13 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release

Confirmed it on 3.0, 3.1, and trunk already, So punting to a future release.

#3 @dd32
13 years ago

Canonical redirection for this case is added with the patch on #12456.

As for why this works at all, It can be traced to get_page_by_path(), which replaces %20 with a space before sanitize_title()'ing it, causing the slug to be determined correctly.

#4 @wonderboymusic
11 years ago

  • Keywords has-patch added; needs-patch removed
  • Milestone changed from Future Release to 3.6

Attached the #12456 patch, which is related - I updated dd32's patch for trunk

#5 @SergeyBiryukov
11 years ago

  • Keywords needs-unit-tests added

#6 @ryan
11 years ago

  • Milestone changed from 3.6 to Future Release

#7 in reply to: ↑ 2 @jamescollins
11 years ago

  • Version changed from 3.2 to 3.0

Replying to dd32:

Confirmed it on 3.0, 3.1, and trunk already

Setting version as per dd32's note.

10 years ago

Unit tests

#8 @jared_smith
10 years ago

  • Keywords needs-unit-tests removed

I'm not sure the attached patch actually solves the stated problem. I created the 17653-tests.patch unit test to ensure that the patch worked, and at least in my environment, it hasn't helped at all.

#9 @dd32
10 years ago

  • Owner dd32 deleted
  • Status changed from accepted to assigned

10 years ago

Removing from trunk as per #30284

#10 @chriscct7
8 years ago

  • Keywords needs-refresh added

#11 @jared_smith
8 years ago

  • Keywords has-unit-tests needs-patch added; has-patch needs-refresh removed

The tests still apply, but the patch still needs work because it doesn't completely solve the problem it sets out to correct.

#13 @SergeyBiryukov
7 years ago

  • Owner set to SergeyBiryukov
  • Status changed from assigned to accepted
Note: See TracTickets for help on using tickets.