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

Preserve query parameters

Open feasgal opened this issue 1 year ago • 3 comments

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.

feasgal avatar Oct 12 '24 00:10 feasgal

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

https://github.com/mkdocs/mkdocs-redirects/blob/32ccfd0ce36bcd25df66a5c58a3e1a0916f2a767/mkdocs_redirects/plugin.py#L17-L32

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

pawamoy avatar Oct 12 '24 12:10 pawamoy

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:

  • https://github.com/nypesap/mkdocs-nype/blob/d0cb088b56ead6c3ea5c13349ceb8b4f660ac3a7/mkdocs_nype/plugins/custom_redirects/plugin.py#L38-L42
  • https://github.com/squidfunk/mkdocs-material/blob/master/src/templates/redirect.html

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

kamilkrzyskow avatar Nov 09 '24 22:11 kamilkrzyskow

Hi @feasgal, thanks for the feature request. Would you like to try and send a PR for it?

I submitted one through my company's account (pacenathan). Sorry for the delay as we were working on a big release ourselves.

feasgal avatar Jul 14 '25 21:07 feasgal