41
41
ServeRedirectMixin ,
42
42
StorageFileNotFound ,
43
43
)
44
+ from readthedocs .proxito .views .utils import allow_readme_html_at_root_url
44
45
from readthedocs .redirects .exceptions import InfiniteRedirectException
45
46
from readthedocs .storage import build_media_storage
46
47
@@ -641,12 +642,16 @@ def _get_index_file_redirect(self, request, project, version, filename, full_pat
641
642
- /en/latest/foo -> /en/latest/foo/README.html
642
643
- /en/latest/foo/ -> /en/latest/foo/README.html
643
644
"""
644
- tryfiles = ["index.html" , "README.html" ]
645
- # If the path ends with `/`, we already tried to serve
646
- # the `/index.html` file, so we only need to test for
647
- # the `/README.html` file.
648
- if full_path .endswith ("/" ):
649
- tryfiles = ["README.html" ]
645
+
646
+ if allow_readme_html_at_root_url ():
647
+ tryfiles = ["index.html" , "README.html" ]
648
+ # If the path ends with `/`, we already tried to serve
649
+ # the `/index.html` file, so we only need to test for
650
+ # the `/README.html` file.
651
+ if full_path .endswith ("/" ):
652
+ tryfiles = ["README.html" ]
653
+ else :
654
+ tryfiles = ["index.html" ]
650
655
651
656
tryfiles = [
652
657
(filename .rstrip ("/" ) + f"/{ tryfile } " ).lstrip ("/" ) for tryfile in tryfiles
@@ -664,7 +669,7 @@ def _get_index_file_redirect(self, request, project, version, filename, full_pat
664
669
log .info ("Redirecting to index file." , tryfile = tryfile )
665
670
# Use urlparse so that we maintain GET args in our redirect
666
671
parts = urlparse (full_path )
667
- if tryfile .endswith ("README.html" ):
672
+ if allow_readme_html_at_root_url () and tryfile .endswith ("README.html" ):
668
673
new_path = parts .path .rstrip ("/" ) + "/README.html"
669
674
else :
670
675
new_path = parts .path .rstrip ("/" ) + "/"
0 commit comments