Skip to content

Redirects don't work if the url includes /projects/foo #7552

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
ltalirz opened this issue Oct 9, 2020 · 2 comments · Fixed by #10179
Closed

Redirects don't work if the url includes /projects/foo #7552

ltalirz opened this issue Oct 9, 2020 · 2 comments · Fixed by #10179
Labels
Accepted Accepted issue on our roadmap Feature New feature

Comments

@ltalirz
Copy link

ltalirz commented Oct 9, 2020

Details

It seems that in exact redirects the $rest keyword is treated "verbatim" rather than as the placeholder it is intended to be.

The documentation on exact redirects explains

image

So, I tried setting up the following redirect on the aiida-core RTD project:

image

Expected Result

All requests of the form
https://aiida-core.readthedocs.io/projects/abc
should be redirected to
https://aiida.readthedocs.io/projects/abc

Actual Result

Only the "verbatim" request
https://aiida-core.readthedocs.io/projects/$rest
is redirected to
https://aiida.readthedocs.io/projects/

@humitos
Copy link
Member

humitos commented Oct 12, 2020

Hi! Thanks for your report. The /projects/ part of the URL has a special meaning in Read the Docs and it's used to define subprojects of a project. In your example, abc is a subproject of aiida-core. Read the Docs tries to find the abc subproject and fails. That's why it's returning 404.

The code that produces this is at

log.warning(
'The slug is not subproject of project. subproject_slug=%s project_slug=%s',
subproject_slug, kwargs['project'].slug
)
raise Http404('Invalid subproject slug')

That decorator is executed immediately when the page is tried to be served and the redirects code is not hit at all because the decorator fails:

final_project, lang_slug, version_slug, filename = _get_project_data_from_request( # noqa
request,
project_slug=project_slug,
subproject_slug=subproject_slug,
lang_slug=lang_slug,
version_slug=version_slug,
filename=filename,
)

I'm afraid that this is a current limitation about how redirects with /projects/ in the URL works.

Only the "verbatim" request
https://aiida-core.readthedocs.io/projects/$rest

This redirect works because $rest is interpreted as '' (empty).

  1. RTD tries to access /projects/ page in a project with versions and it fails,
WARNING Invalid URL for project with versions. url=projects/, project=aiida-core [readthedocs.proxito.views.serve:122]
  1. The 404 handler is triggered and found a redirect
Redirecting: from=https://aiida-core.readthedocs.io/projects/ to=https://aiida.readthedocs.org/projects http_status=302 [readthedocs.proxito.views.mixins:233]

(note that $rest does not appear in the from= URL)

@humitos humitos added Accepted Accepted issue on our roadmap Feature New feature labels Oct 12, 2020
@ltalirz
Copy link
Author

ltalirz commented Oct 12, 2020

Thanks a lot @humitos for the detailed analysis!

I see - I was trying to use the redirect in order to work around #7487 (i.e. to fix the broken links in the search results on aiida-core, which wrongly include the /project prefix).

This particular use case will go away once #7487 is fixed, but there is another use case that will remain: if a subproject moves away from a parent project, it would be very useful to be able to still redirect requests to a different documentation site - thanks for accepting this as a feature request.

@stsewd stsewd changed the title Redirects: $rest keyword not working as documented in exact redirect Redirects don't work if the url includes /projects/foo May 26, 2021
stsewd added a commit that referenced this issue Mar 23, 2023
This is only available in the new implementation.

Closes #7552
stsewd added a commit that referenced this issue Mar 27, 2023
This is only available in the new implementation.

Closes #7552
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Accepted issue on our roadmap Feature New feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants