hm-redirects icon indicating copy to clipboard operation
hm-redirects copied to clipboard

Redirecting to a destination with state

Open svandragt opened this issue 2 years ago • 2 comments

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?

svandragt avatar Apr 17 '23 15:04 svandragt

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.

roborourke avatar Apr 17 '23 15:04 roborourke

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

svandragt avatar Apr 18 '23 07:04 svandragt