jimporter / mike

Manage multiple versions of your MkDocs-powered documentation via Git
BSD 3-Clause "New" or "Revised" License
528 stars 47 forks source link

Latest redirection is losing URL query string #127

Closed lmazureNX closed 1 year ago

lmazureNX commented 1 year ago

Hello @jimporter,

We have an issue similar to #57. We have some doc sites for some open source projects (e.g. https://tm-en.doc.squashtest.com). We are trying to promote our projects by several means and we expect to use Plausible (https://plausible.io) and UTM parameters (https://en.wikipedia.org/wiki/UTM_parameters) in order to see what channels are effective. So, for example, we will use URLs ending with "?utm_source=email" in our email newsletter. But the redirection via latest is losing these parameters. I know that we can define our own redirect.html template to handle this. But the scenario I describe seems pretty generic and I believe it would be worthwhile to support it. (I do not see drawbacks to implementing this.)

Actual behavior

Redirected address from latest to some the latest version drops the ?search fragment from the URL.

Expected behavior

Redirect to exact address without dropping ?search fragment.

Steps to reproduce the bug

https://tm-en.doc.squashtest.com/latest/index.html?utm_source=email is redirected to https://tm-en.doc.squashtest.com/v4/index.html instead of https://tm-en.doc.squashtest.com/v4/index.html?utm_source=email.

Possible fix

Replacing in redirect.html

window.location.replace("{{href}}" + window.location.hash);

with

window.location.replace("{{href}}" + window.location.search + window.location.hash);

would do the job.

Related Issue

#57

And that for providing this useful tool!

jimporter commented 1 year ago

That seems reasonable, and like you say, I don't think there should be any risks to doing something like this.