Make WordPress Core

Opened 10 years ago

Last modified 2 months ago

#40032 new defect (bug)

Automatic redirects with _wp_old_slug won't mantain GET parameters if present

Reported by: DrLightman Owned by:
Priority: normal Milestone: Awaiting Review
Component: Permalinks Version: 2.1
Severity: normal Keywords: has-patch needs-testing has-unit-tests
Cc: Focuses:

Description

If for example links come up with GET parameters, for example utm parameters for analytics, they get stripped before the redirect.

post_name = 'new-slug'
_wp_old_slug = 'old-slug'

​http://example.org/old-slug/?utm_source=test1&utm_medium=test2&utm_campaign=test3

Wordpress will build the link for the redirect to the new slug without any GET parameter:

​http://example.org/new-slug/

I think it should mantein them instead:

​http://example.org/new-slug/?utm_source=test1&utm_medium=test2&utm_campaign=test3

I'm not even sure if this should be classified as a bug, if it's the correct behaviour or not. I'll let you judge.

Attachments (3)

40032.patch​ (562 bytes ) - added by desrosj 10 years ago.
Preserve $_GET params on _wp_old_slug redirects
40032.2.patch​ (492 bytes ) - added by brookedot 6 years ago.
trac-40032-pr-12633-playground.png​ (65.4 KB ) - added by arkaprabhachowdhury 2 months ago.
WordPress Playground test setup for PR #12633.

Download all attachments as: .zip

Change History (12)

#1 @SergeyBiryukov
10 years ago

  • Summary Automatic redirects with _wp_old_slug won't mantein GET parameters if present → Automatic redirects with _wp_old_slug won't mantain GET parameters if present

@desrosj
10 years ago

Preserve $_GET params on _wp_old_slug redirects

#2 @desrosj
10 years ago

  • Keywords has-patch needs-testing added

#3 @brookedot
6 years ago

  • Version → 2.1

#4 @brookedot
6 years ago

  • Keywords needs-refresh added

#5 @brookedot
6 years ago

I'll give refreshing @desrosj's patch a go. As old_slug_redirect_url is filterable there is a workaround to add the query parameters with that filter but I think having it fixed in core would be great.

@brookedot
6 years ago

#6 @brookedot
6 years ago

  • Keywords needs-refresh removed

This ticket was mentioned in ​PR #12633 on ​WordPress/wordpress-develop by ​@arkaprabhachowdhury.


3 months ago
#7

  • Keywords has-unit-tests added

Trac ticket: https://core.trac.wordpress.org/ticket/40032 | Preserves request query arguments when wp_old_slug_redirect() redirects an old post slug, with focused PHPUnit regression coverage.

@arkaprabhachowdhury
2 months ago

WordPress Playground test setup for PR #12633.

#8 @arkaprabhachowdhury
2 months ago

Test Report

Tested PR #12633 in WordPress Playground.

Steps:

  1. Renamed a published post slug from hello-world to redirect-target.
  2. Opened the previous permalink with utm_source=playground and campaign=old-slug-test.
  3. Confirmed WordPress redirected to redirect-target while retaining both query arguments.

Result:
The patch works as expected. The old-slug redirect preserves non-core query arguments. The attached screenshot shows the prepared Playground post.

#9 @arkaprabhachowdhury
2 months ago

Opened [PR #12633](​https://github.com/WordPress/wordpress-develop/pull/12633) to address this ticket. The PR includes focused regression coverage, and its validation details are recorded in the PR description.

I picked this up because the ticket describes a concrete core behavior or edge case that remains relevant in current WordPress. The proposed change is intentionally scoped to the ticket and is submitted here for code review, with the technical discussion remaining on this ticket.

Note: See TracTickets for help on using tickets.