humanmade / hm-redirects

Fast and scalable redirects plugin for WordPress
29 stars 11 forks source link

Redirecting to a destination with state #71

Open svandragt opened 1 year ago

svandragt commented 1 year ago

I'm looking at the plugin and hit what seems to be the perennial issue.

if you setup a redirect from /a to /b , after creation you can add a querystring and hash to the url and it will be appended to the redirect. Great so far. (/a?tab=2#myheading redirects to /b?tab=2#myheading)

However if you say want to redirect to a destination containing a hardcoded querystring/hash then that's not possible as it gets stripped from the redirect on save. (from /a to /b?tab=2#myheading.

The use case is publishing a short url in print and it loading say a page with certain state. Another usecase is a redirect to a javascript app that handles internal state.

I might be able to have time to look at this. Is it desired, or have people solved this another way?

roborourke commented 1 year ago

For reference, some earlier work on this https://github.com/humanmade/hm-redirects/pull/55

Ultimately it was very hard to make this work in a performant way but always good to have another pair of eyes on a problem.

svandragt commented 1 year ago

After discussions a smaller version of the problem that #55 tries to tackle is simply allow query string and url hashes in the destination, merging with ( and overwriting) any in the input.

This avoids complexity and performance issues:

Example: with a redirect from /a to /b?tab=2#myheading

1) and a user input of /a?tab=1 or /a the result is the destination,

2) for /a?what=this the result is /b?what=this&tab=2#myheading