Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve query parameters #64

Open
feasgal opened this issue Oct 12, 2024 · 2 comments
Open

Preserve query parameters #64

feasgal opened this issue Oct 12, 2024 · 2 comments

Comments

@feasgal
Copy link

feasgal commented Oct 12, 2024

Currently, if these are the redirects:

    - redirects:
        redirect_maps:
            index.md: home.md

then a link to mydomain.com/index.html?q=example will redirect to mydomain.com/home.html.

I would want it to preserve the query parameters, and redirect to mydomain.com/home.html?q=example.

@pawamoy
Copy link
Contributor

pawamoy commented Oct 12, 2024

Hi @feasgal, thanks for the feature request. Would you like to try and send a PR for it? This plugin currently redirects using Javascript:

HTML_TEMPLATE = """
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Redirecting...</title>
<link rel="canonical" href="{url}">
<meta name="robots" content="noindex">
<script>var anchor=window.location.hash.substr(1);location.href="{url}"+(anchor?"#"+anchor:"")</script>
<meta http-equiv="refresh" content="0; url={url}">
</head>
<body>
You're being redirected to a <a href="{url}">new destination</a>.
</body>
</html>
"""

You could probably use one of the solution mentioned in https://stackoverflow.com/a/901144/3451029 to preserve query params.

@kamilkrzyskow
Copy link

kamilkrzyskow commented Nov 9, 2024

Hello 👋 ,
at mkdocs-nype we are using a custom HTML_TEMPLATE based on the Material theme's redirect.html template as it does preserve the query with JS when supported, otherwise it falls back to meta refresh tag:

You can override the current HTML_TEMPLATE in a similar fashion using a hook before it's implemented here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants