Skip to content

No wildcard redirects possible? #3465

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

Closed
marcelstoer opened this issue Dec 29, 2017 · 12 comments
Closed

No wildcard redirects possible? #3465

marcelstoer opened this issue Dec 29, 2017 · 12 comments
Labels
Improvement Minor improvement to code Needed: design decision A core team decision is required

Comments

@marcelstoer
Copy link
Contributor

marcelstoer commented Dec 29, 2017

When we started with RTD & MkDocs two years ago we tried to work around some l10n shortcomings ourselves. Turns out we don't need that all; all files can be moved up one level in the directory tree. To avoid dead links we'd like to configure wild card redirects to omit that extra folder in the URL.

Examples:

In short, in mod_rewrite terms this would be /$lang/$version/en/(.*) -> /$lang/$version/$1.

I studied the three redirect options in the documentation and ran a few tests but a) I'm either too stupid to get it or b) then such wild card redirects really aren't supported. If b) then https://github.com/honzajavorek/rtd-redirects might come in handy for us.

@RichardLitt RichardLitt added Improvement Minor improvement to code Needed: design decision A core team decision is required labels Dec 30, 2017
@marcelstoer
Copy link
Contributor Author

The 'Enhancement' tag added by @RichardLitt suggests that it's b) indeed...what a relief 😜

@RichardLitt
Copy link
Member

Best guess on my part. Let's see what the others have to say. :)

@vidartf
Copy link
Contributor

vidartf commented Feb 6, 2018

I need to do something similar, so I looked at code here: https://github.com/rtfd/readthedocs.org/blob/96f6da57d89a37bdfa6b99de93e8ae6d09e2a586/readthedocs/redirects/models.py

There does not seem to be any wildcards, but I see that exact redirects have a '$rest' parameter. I think this will allow you to do what you want, by the following pattern:

  • from: /$lang/$version/en/$rest
  • to: /$lang/$version/
    (you might need to tweak the start, not sure how from/to gets set before entering code linked).

Note: The $rest bit seems not to be documented, so here be dragons.

@marcelstoer
Copy link
Contributor Author

You mean https://github.com/rtfd/readthedocs.org/blob/96f6da57d89a37bdfa6b99de93e8ae6d09e2a586/readthedocs/redirects/models.py#L134 right? I don't see support for either $lang or $version in the code though.

I was recently testing redirects w/ modifying my file structure first (i.e. I didn't have any invalid links) and was then wondering why my redirect rules weren't applied at all. Turns out they're only active after HTTP 404 was detected:

Since we serve documentation in a highly available way, we do not run any logic when we’re serving documentation. This means that redirects will only happen in the case of a 404 File Not Found.

@vidartf
Copy link
Contributor

vidartf commented Feb 9, 2018

I don't see support for either $lang or $version in the code though.

Yes, looking closer on this I see that. Are you sure your case can't be covered by the prefix redirect?

@fantix
Copy link

fantix commented May 17, 2018

I have a case needing wildcard redirects that one language of translation is completely hosted somewhere else, so I'd like to redirect /en/(.*) to https://else.where/en/$1.

@stsewd
Copy link
Member

stsewd commented Sep 6, 2018

The rest keyword is now documented https://docs.readthedocs.io/en/latest/user-defined-redirects.html#exact-redirects Looks like it solves all the problems here, not sure if a wildcard is still needed after that.

@marcelstoer
Copy link
Contributor Author

Thanks for that extra documentation. So, are you convinced that I could solve the original requirement (as per my description) with an exact redirect? I'm not convinced yet. What would you say is the rule I'd have to configure?

@stsewd
Copy link
Member

stsewd commented Sep 6, 2018

I believe /en/latest/en/$rest -> /en/latest/ should work (I just tested this and it works!). I'm not completely sure, but for me looks like the rest keyword is the wildcard redirect p:

@humitos
Copy link
Member

humitos commented Nov 15, 2018

@marcelstoer could you please test the solution that @stsewd provided? I think that should achieve your goal.

I want to have something actionable on this issue or close it.

@stsewd stsewd added the Needed: more information A reply from issue author is required label Dec 12, 2018
@no-response
Copy link

no-response bot commented Jan 10, 2019

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further. Thanks!

@no-response no-response bot closed this as completed Jan 10, 2019
@marcelstoer
Copy link
Contributor Author

@humitos it's great that you documented this behavior back in August in f434859. What I didn't get initially is that $rest doesn't need to be repeated in the to-URL (thinking about regex capturing groups and replacements). Triggered by the bot message above I ran a few tests in my project and all is well. Thanks again for your contributions and support.

@no-response no-response bot removed the Needed: more information A reply from issue author is required label Jan 10, 2019
@no-response no-response bot reopened this Jan 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Improvement Minor improvement to code Needed: design decision A core team decision is required
Projects
None yet
Development

No branches or pull requests

6 participants