Move `redirect_filename` to where it's needed
@@ -180,19 +180,6 @@ class ServeError404Base(ServeRedirectMixin, View):
filename=kwargs.get('filename', ''),
)
- # ``redirect_filename`` is the path without ``/<lang>/<version>`` and
- # without query, starting with a ``/``. This matches our old logic:
- # https://github.com/readthedocs/readthedocs.org/blob/4b09c7a0ab45cd894c3373f7f07bad7161e4b223/readthedocs/redirects/utils.py#L60
- # We parse ``filename`` to remove the query from it
- schema, netloc, path, params, query, fragments = urlparse(filename)
- redirect_filename = path
-
- # we can't check for lang and version here to decide if we need to add
- # the ``/`` or not because ``/install.html`` is a valid path to use as
- # redirect and does not include lang and version on it. It should be
- # fine always adding the ``/`` to the beginning.
- redirect_filename = '/' + redirect_filename.lstrip('/')
-
storage_root_path = final_project.get_storage_path(
type_='html',
version_slug=version_slug,
@@ -231,6 +218,19 @@ class ServeError404Base(ServeRedirectMixin, View):
# (from URL == to URL)
return HttpResponseRedirect(redirect_url)
+ # ``redirect_filename`` is the path without ``/<lang>/<version>`` and
+ # without query, starting with a ``/``. This matches our old logic:
+ # https://github.com/readthedocs/readthedocs.org/blob/4b09c7a0ab45cd894c3373f7f07bad7161e4b223/readthedocs/redirects/utils.py#L60
+ # We parse ``filename`` to remove the query from it
+ schema, netloc, path, params, query, fragments = urlparse(filename)
+ redirect_filename = path
+
+ # we can't check for lang and version here to decide if we need to add
+ # the ``/`` or not because ``/install.html`` is a valid path to use as
+ # redirect and does not include lang and version on it. It should be
+ # fine always adding the ``/`` to the beginning.
+ redirect_filename = '/' + redirect_filename.lstrip('/')
+
# Check and perform redirects on 404 handler
# NOTE: this redirect check must be done after trying files like
# ``index.html`` and ``README.html`` to emulate the behavior we had when
