Opened 14 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 | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | 3.0 |
Component: | Canonical | Keywords: | has-unit-tests needs-patch |
Focuses: | Cc: |
Description
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: http://jamesc.id.au/test-page/
This page is accessible via:
- http://jamesc.id.au/test%20page/
- http://jamesc.id.au/test%20%20page/
- http://jamesc.id.au/test%20%20%20page/
- http://jamesc.id.au/test%20%20%20%20page/
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)
Change History (17)
#2
follow-up:
↓ 7
@
14 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
@
14 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
@
12 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
#8
@
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.
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.