@@ -673,6 +673,43 @@ def setUp(self):
673
673
future_default_true = True ,
674
674
)
675
675
676
+ def test_redirect_using_projects_prefix (self ):
677
+ """
678
+ Test that we can support redirects using the ``/projects/`` prefix.
679
+
680
+ https://github.com/readthedocs/readthedocs.org/issues/7552
681
+ """
682
+ redirect = fixture .get (
683
+ Redirect ,
684
+ project = self .project ,
685
+ redirect_type = "exact" ,
686
+ from_url = "/projects/$rest" ,
687
+ to_url = "https://example.com/projects/" ,
688
+ )
689
+ self .assertEqual (self .project .redirects .count (), 1 )
690
+ r = self .client .get (
691
+ "/projects/deleted-subproject/en/latest/guides/install.html" ,
692
+ HTTP_HOST = "project.dev.readthedocs.io" ,
693
+ )
694
+ self .assertEqual (r .status_code , 302 )
695
+ self .assertEqual (
696
+ r ["Location" ],
697
+ "https://example.com/projects/deleted-subproject/en/latest/guides/install.html" ,
698
+ )
699
+
700
+ redirect .from_url = "/projects/not-found/$rest"
701
+ redirect .to_url = "/projects/subproject/"
702
+ redirect .save ()
703
+ r = self .client .get (
704
+ "/projects/not-found/en/latest/guides/install.html" ,
705
+ HTTP_HOST = "project.dev.readthedocs.io" ,
706
+ )
707
+ self .assertEqual (r .status_code , 302 )
708
+ self .assertEqual (
709
+ r ["Location" ],
710
+ "http://project.dev.readthedocs.io/projects/subproject/en/latest/guides/install.html" ,
711
+ )
712
+
676
713
677
714
@override_settings (PUBLIC_DOMAIN = "dev.readthedocs.io" )
678
715
class UserForcedRedirectTests (BaseDocServing ):
0 commit comments