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

Option to override use_directory_urls for redirect sources #59

Closed
andgineer opened this issue Mar 14, 2024 · 6 comments
Closed

Option to override use_directory_urls for redirect sources #59

andgineer opened this issue Mar 14, 2024 · 6 comments

Comments

@andgineer
Copy link

Now mkdocs-redirect create both source and target redirect URLs based on mkdocs option use_directory_urls
But if we had a legacy site with file-style URLs and now we need redirects from that old legacy to new shiny site with fancy URL redirects we are out of luck :(

So I end with that hack:
https://github.com/andgineer/TRegExpr/blob/master/docs/fix_folder_redirects.py

To fix that for example we can have mkdocs-redict option use different use_directory_urls for the redirect sources.

Also we could specify that for each redirect.

@andgineer andgineer changed the title Option to override use_directory_urls Option to override use_directory_urls for redirect sources Mar 14, 2024
@feasgal
Copy link

feasgal commented Aug 2, 2024

I'm looking for almost the same thing. It would probably end up being covered by the same update to mkdocs-redirects.

I have a legacy site with file-style URLs, because we used to deliver the docs with our SDK as well as online. Now our docs are online-only and we want to set use_directory_urls: true, but we aren't re-organizing the documentation. I need our customers' bookmarks and links that currently go to path/to/file.html to redirect to path/to/file/ or path/to/file/index.html after I make the switch. I can't find a currently-handled syntax that will accomplish this.

@pawamoy
Copy link
Contributor

pawamoy commented Aug 2, 2024

Possible workaround:

plugins:
- redirects:
    redirect_maps:
      old/url.html.md: new/page.md

What's fun is that it will create a directory URL named old/url.html/, and since the trailing slash is automatically appended (with a redirect), it means you can actually go to old/url.html, which will redirect you to old/url.html/, which will redirect you to new/page/ 🤣

I have successfully used this technique for my blog in the past 🙂

plugins:
  - search
  - redirects:
      redirect_maps:
        2018/02/01/docker-compose-django-postgres-nginx.html.md: posts/docker-compose-django-postgres-nginx.md
        2017/05/31/python-static-code-analysis-tools.html.md: posts/python-static-code-analysis-tools.md
        2016/12/07/documentation-in-your-shell-scripts-using-shellman.html.md: posts/documentation-in-your-shell-scripts-using-shellman.md
        2016/12/07/write-and-use-a-tox-plugin-from-inside-your-package.html.md: posts/write-and-use-a-tox-plugin-from-inside-your-package.md
        2016/04/06/django-dashboard-with-suit-and-highcharts.html.md: posts/django-dashboard-with-suit-and-highcharts.md

@feasgal
Copy link

feasgal commented Aug 2, 2024

That's a really interesting proposition. I'll have to try it. So far everything I've tried has ended up with an infinite redirect loop because the directory structure isn't changing, just that one use_directory_urls config setting.

@feasgal
Copy link

feasgal commented Aug 2, 2024

It works! Now as long as that workaround isn't a bug that gets 'fixed'...

@feasgal
Copy link

feasgal commented Aug 5, 2024

For what it's worth, the 'right' way to do what I was doing is to write a server-side redirect for that URL pattern. And that is exactly what my colleague just did because I hadn't told him I was pursuing it from the docs config side, so we're going with that solution since he's already done it.

But this workaround did work! Thank you for it!

@pawamoy
Copy link
Contributor

pawamoy commented Aug 6, 2024

I'd be happy to confirm that this behavior is not a bug and therefore will not be "fixed", but I'm just a passing-by maintainer 🙂 I'll close anyway! If the original authors, other maintainers, or impacted users disagree, we'll reopen.

@pawamoy pawamoy closed this as not planned Won't fix, can't repro, duplicate, stale Aug 6, 2024
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