diff --git a/readthedocs/proxito/tests/test_old_redirects.py b/readthedocs/proxito/tests/test_old_redirects.py index 85b0aab6b1a..807c4b039a5 100644 --- a/readthedocs/proxito/tests/test_old_redirects.py +++ b/readthedocs/proxito/tests/test_old_redirects.py @@ -251,6 +251,13 @@ def test_redirect_root(self): "http://project.dev.readthedocs.io/en/latest/faq.html", ) + # Prefix redirects should match the whole path. + with self.assertRaises(Http404): + self.client.get( + "/en/latest/woot/faq.html", + headers={"host": "project.dev.readthedocs.io"}, + ) + def test_redirect_page(self): Redirect.objects.create( project=self.project, diff --git a/readthedocs/redirects/querysets.py b/readthedocs/redirects/querysets.py index 6cee3179882..63b258214c7 100644 --- a/readthedocs/redirects/querysets.py +++ b/readthedocs/redirects/querysets.py @@ -64,7 +64,7 @@ def get_redirect_path_with_status( ) prefix = Q( redirect_type="prefix", - path__startswith=F("from_url"), + full_path__startswith=F("from_url"), ) page = Q( redirect_type="page",