WordPress.org

Make WordPress Core

Opened 12 years ago

Last modified 3 months ago

#4328 reviewing enhancement

Redirect Old Slugs feature needs to redirect slugs for pages, not just posts, and redirect old permalink structure

Reported by: Denis-de-Bernardy Owned by: SergeyBiryukov
Milestone: Future Release Priority: normal
Severity: normal Version: 2.2
Component: Canonical Keywords: needs-unit-tests needs-patch
Focuses: Cc:

Description

Create a page, browse to it, edit it, change its slug, WP redirects to the old page's slug and serves a 404. Wasn't WP 2.1 or WP 2.2 supposed to make the redirect old slug feature built-in?

Along the same lines, it would be sweet if instead of simply redirect old slugs, WP would redirect old urls. When the date changes, when the page parent changes, or when the permalink structure changes, the url changes but neither of WP, the redirect old slug plugin, the permalink redirect plugin, or anything else catches this.

Attachments (4)

4328.diff (1.1 KB) - added by mdawaffe 10 years ago.
4328.patch (1.2 KB) - added by SergeyBiryukov 9 years ago.
4328.1.diff (6.8 KB) - added by soulseekah 18 months ago.
Revival
4328.tests.diff (2.3 KB) - added by soulseekah 18 months ago.
Page tests

Download all attachments as: .zip

Change History (49)

#1 @Denis-de-Bernardy
12 years ago

adding to the above, the workflow would be:

on post save, cache the url in a custom field. if url is different, append previous value to the old urls.

on permalink structure change, do the above for every post and page on the site.

extra benefit: scanning for which post is requested can be simplified in many cases to something like: select from posts inner join postmeta where url_cache.

D.

#2 @rob1n
12 years ago

  • Milestone changed from 2.2.1 to 2.2.2

#3 @markjaquith
12 years ago

  • Milestone changed from 2.2.2 to 2.4
  • Type changed from defect to enhancement

WP 2.1+ has it built in, but it only works with posts (by design). I just tested it on Trunk and 2.2, and it works as expected for posts.

Having it work for pages or having it track more than slug changes would be a new feature, so it doesn't belong in a 2.2.x release.

#4 @JeremyVisser
12 years ago

  • Summary changed from redirect old slug feature is very broken to Redirect Old Slugs feature needs to redirect slugs for pages, not just posts, and redirect old permalink structure

#6 @Denis-de-Bernardy
12 years ago

Any odds we'll see this in an early 2.5.x?

#7 @thee17
12 years ago

  • Milestone changed from 2.5 to 2.6

#8 @Denis-de-Bernardy
10 years ago

  • Component changed from General to Permalinks
  • Owner changed from anonymous to ryan

#9 @Denis-de-Bernardy
10 years ago

  • Component changed from Permalinks to Canonical
  • Owner changed from ryan to markjaquith

#10 @westi
10 years ago

  • Milestone changed from 2.9 to Future Release

As we are now feature frozen it is too late to include this into 2.9.

Moving to Future Release as there is currently no patch.

@mdawaffe
10 years ago

#11 @mdawaffe
10 years ago

4328.diff turns old slug redirect on for pages.

Two line patch seems to work fine... what are the edge cases?

Works with top level pages and child pages.

#12 @mdawaffe
10 years ago

comment:ticket:3202:2 by markjaquith says

Only works on posts. There doesn't seem to be a clean way of recognizing failed Page attempts... of course there is always my "Page Links To" plugin to take care of that. ;-)

Quote is 3 years old. Either there are some cases I didn't think of or it's no longer true :)

#13 @mdawaffe
10 years ago

  • Keywords has-patch added

#14 @dd32
10 years ago

The only side effect to this would be creating a page AND post of the same name, and then renaming one or both of them.. It might not have the intended path to follow through?

#16 @dd32
9 years ago

See Also: #15140

#17 @SergeyBiryukov
9 years ago

  • Keywords needs-refresh added

Related: #9825

#18 @SergeyBiryukov
9 years ago

  • Keywords needs-refresh removed

@SergeyBiryukov
9 years ago

#19 @SergeyBiryukov
9 years ago

According to Denis' comment on #15140:

If both the slug and the parent change, the redirect doesn't work.

However it seems to be working on current trunk (with the refreshed patch).

#20 @dd32
8 years ago

Closed #18318 as a Duplicate

#21 @varun21
8 years ago

When are we expecting this to land into the production distro? Tnx.

#22 @varun21
8 years ago

  • Cc varun21 added

#23 @SergeyBiryukov
7 years ago

Just stumbled upon this once again. I thought that _wp_old_slug works for pages as well.

Last edited 7 years ago by SergeyBiryukov (previous) (diff)

#24 @SergeyBiryukov
6 years ago

#25989 was marked as a duplicate.

#25 @TwanVermeulen
5 years ago

Can anyone tell when this enhancement will be implemented?

#26 @swissspidy
4 years ago

  • Keywords needs-refresh needs-unit-tests added

#27 @swissspidy
3 years ago

#34489 was marked as a duplicate.

This ticket was mentioned in Slack in #polyglots by sergey. View the logs.


2 years ago

This ticket was mentioned in Slack in #core-editor by swissspidy. View the logs.


2 years ago

#30 @ehau
2 years ago

This is still needed. It's confusing to have different behaviors for posts and pages. A setting to be able to turn this off would be good also.

10 years and counting...

#31 follow-up: @dd32
19 months ago

It's about time that this happens - does anyone want to pick this up and own it?

@SergeyBiryukov 4328.patch seems like it's really the only thing needed here (I've not looked into it) do you have any interest in running with this?

#32 @SergeyBiryukov
18 months ago

  • Milestone changed from Future Release to 5.0

#33 in reply to: ↑ 31 @dd32
18 months ago

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

Replying to dd32:

4328.patch seems like it's really the only thing needed here (I've not looked into it)

I've been thinking about this, with an intent of trying some code out, however I think i should also note here this thought:

  • For hierarchical post types, the _wp_old_slug value should be the full hierarchical path, for example, given /foo/bar/ and /bar/ being moved to /subpage/foo/bar/ and /subpage/bar/ respectively, I'd expect /foo/bar/ and /bar/ to redirect to the correct locations.

The current patch doesn't do that, as it'd only store bar for both of these pages (Well, it wouldn't actually, as it only compares on slugs, but ignoring that..)

#34 @soulseekah
18 months ago

Very interested in seeing this happen. I'd like to give it a shot. Will send something in tomorrow, probably.

@soulseekah
18 months ago

Revival

#35 @soulseekah
18 months ago

Related to what these guys are doing #15953 I hope we don't clash, especially with exotic rewrite rules, parent page structures, etc.

Here's a refresh that allow all custom post types through, not just pages.

I'm sure there are edge cases, but let's just get things going. We'll need a lot of new tests.

@soulseekah
18 months ago

Page tests

#36 @SergeyBiryukov
17 months ago

#44008 was marked as a duplicate.

#37 @pento
11 months ago

  • Milestone changed from 5.0 to 5.1

This ticket was mentioned in Slack in #core by swissspidy. View the logs.


10 months ago

This ticket was mentioned in Slack in #core-php by sergey. View the logs.


9 months ago

#40 @SergeyBiryukov
9 months ago

  • Owner changed from markjaquith to SergeyBiryukov
  • Status changed from new to reviewing

#41 @pento
8 months ago

  • Milestone changed from 5.1 to Future Release

This needs testing and reviewing.

This ticket was mentioned in Slack in #core-docs by skorasaurus. View the logs.


6 months ago

This ticket was mentioned in Slack in #core by skorasaurus. View the logs.


6 months ago

#44 @skorasaurus
6 months ago

This ticket's original description is from 12 years ago and WordPress has changed since then and what was in the original description is no longer applicable.

WordPress will redirect to the intended page from its old url to its new url in the following scenarios:

I've only (manually) tested this on the post_type of 'page' and when the permalink setting (wp-admin/options-permalink.php) is set to post-name.

when the slug is changed;
when a page has a changed parent page
when the parent's page slug is changed.
when a parent page is added.
when its parent page is made to have another parent page.

The only scenario that I had found to not work and what made me find this ticket in the first place:

is that redirects will not work as expected when is when a page is added to have a 3rd level parent page.

For example, a page with the slug of "3d-printing" and has two levels of parent pages (so its full url is: "subjects/technology/3d-printing/" is made to have a 3rd parent page (the new url is "library/subjects/technology/3d-printing/") ;
the redirect will not occur, and the user receives a 404.

This ticket was mentioned in Slack in #meta by dd32. View the logs.


3 months ago

Note: See TracTickets for help on using tickets.