We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Wrong redirect on localized home page
Examples:
```
▶ curl -I https:/developer.mozilla.org/fr
HTTP/2 301
location: /fr/docs/fr
server: gunicorn/20.0.4
```
The exact same is happening to `ja`

But other locales seem fine, e.g.
```
▶ curl -I https:/developer.mozilla.org/de
HTTP/2 301
location: /de/
server: gunicorn/20.0.4
```
The exact same is happening to `sv-SE` and `en-US`. 

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `kuma/wiki/views/legacy.py`
Content:
```
1 from django.conf import settings
2 from django.http import Http404
3 from django.shortcuts import redirect
4 
5 from kuma.core.decorators import shared_cache_control
6 
7 from ..constants import LEGACY_MINDTOUCH_NAMESPACES
8 from ..models import Document, Revision
9 
10 
11 # Legacy MindTouch redirects.
12 
13 
14 def mindtouch_namespace_to_kuma_url(locale, namespace, slug):
15     """
16     Convert MindTouch namespace URLs to Kuma URLs.
17 
18     For special namespaces like Talk:, User:, etc., convert to the
19     approproate new URL, converting MT locales to Kuma locales.
20     If the locale cannot be correctly determined, fall back to en-US
21     """
22     new_locale = new_slug = None
23     if namespace in ("Talk", "Project", "Project_talk"):
24         # These namespaces carry the old locale in their URL, which
25         # simplifies figuring out where to send them.
26         mt_locale, _, doc_slug = slug.partition("/")
27         new_locale = settings.MT_TO_KUMA_LOCALE_MAP.get(mt_locale, "en-US")
28         new_slug = "%s:%s" % (namespace, doc_slug)
29     elif namespace == "User":
30         # For users, we look up the latest revision and get the locale
31         # from there.
32         new_slug = "%s:%s" % (namespace, slug)
33         try:
34             # TODO: Tests do not include a matching revision
35             rev = Revision.objects.filter(document__slug=new_slug).latest("created")
36             new_locale = rev.document.locale
37         except Revision.DoesNotExist:
38             # If that doesn't work, bail out to en-US.
39             new_locale = "en-US"
40     else:
41         # Templates, etc. don't actually have a locale, so we give
42         # them the default.
43         new_locale = "en-US"
44         new_slug = "%s:%s" % (namespace, slug)
45     if new_locale:
46         # TODO: new_locale is unused, no alternate branch
47         new_url = "/%s/docs/%s" % (locale, new_slug)
48     return new_url
49 
50 
51 def mindtouch_to_kuma_url(locale, path):
52     """
53     Convert valid MindTouch namespace URLs to Kuma URLs.
54 
55     If there is an appropriate Kuma URL, then it is returned.
56     If there is no appropriate Kuma URL, then None is returned.
57     """
58     if path.startswith("%s/" % locale):
59         # Convert from Django-based LocaleMiddleware path to zamboni/amo style
60         path = path.replace("%s/" % locale, "", 1)
61 
62     if path.startswith("Template:MindTouch"):
63         # MindTouch's default templates. There shouldn't be links to
64         # them anywhere in the wild, but just in case we 404 them.
65         # TODO: Tests don't exercise this branch
66         return None
67 
68     if path.endswith("/"):
69         # If there's a trailing slash, snip it off.
70         path = path[:-1]
71 
72     if ":" in path:
73         namespace, _, slug = path.partition(":")
74         # The namespaces (Talk:, User:, etc.) get their own
75         # special-case handling.
76         # TODO: Test invalid namespace
77         if namespace in LEGACY_MINDTOUCH_NAMESPACES:
78             return mindtouch_namespace_to_kuma_url(locale, namespace, slug)
79 
80     # Last attempt: we try the request locale as the document locale,
81     # and see if that matches something.
82     try:
83         doc = Document.objects.get(slug=path, locale=locale)
84     except Document.DoesNotExist:
85         return None
86 
87     location = doc.get_absolute_url()
88     return location
89 
90 
91 @shared_cache_control(s_maxage=60 * 60 * 24 * 30)
92 def mindtouch_to_kuma_redirect(request, path):
93     """
94     Given a request to a Mindtouch-generated URL, generate a redirect
95     to the correct corresponding kuma URL.
96 
97     TODO: Retire this catch-all view and Mindtouch redirects.
98     Safest: Ensure no current content includes these URLs, no incoming links.
99     Middle: Monitor 404s and their referrer headers, fix links after removal.
100     Fastest: Remove it, ignore 404s.
101     """
102     locale = request.LANGUAGE_CODE
103     url = mindtouch_to_kuma_url(locale, path)
104     if url:
105         if "view" in request.GET:
106             url = "%s$%s" % (url, request.GET["view"])
107         return redirect(url, permanent=True)
108     else:
109         raise Http404
110
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/kuma/wiki/views/legacy.py b/kuma/wiki/views/legacy.py
--- a/kuma/wiki/views/legacy.py
+++ b/kuma/wiki/views/legacy.py
@@ -5,7 +5,7 @@
 from kuma.core.decorators import shared_cache_control
 
 from ..constants import LEGACY_MINDTOUCH_NAMESPACES
-from ..models import Document, Revision
+from ..models import Revision
 
 
 # Legacy MindTouch redirects.
@@ -77,15 +77,7 @@
         if namespace in LEGACY_MINDTOUCH_NAMESPACES:
             return mindtouch_namespace_to_kuma_url(locale, namespace, slug)
 
-    # Last attempt: we try the request locale as the document locale,
-    # and see if that matches something.
-    try:
-        doc = Document.objects.get(slug=path, locale=locale)
-    except Document.DoesNotExist:
-        return None
-
-    location = doc.get_absolute_url()
-    return location
+    return None
 
 
 @shared_cache_control(s_maxage=60 * 60 * 24 * 30)

{"golden_diff": "diff --git a/kuma/wiki/views/legacy.py b/kuma/wiki/views/legacy.py\n--- a/kuma/wiki/views/legacy.py\n+++ b/kuma/wiki/views/legacy.py\n@@ -5,7 +5,7 @@\n from kuma.core.decorators import shared_cache_control\n \n from ..constants import LEGACY_MINDTOUCH_NAMESPACES\n-from ..models import Document, Revision\n+from ..models import Revision\n \n \n # Legacy MindTouch redirects.\n@@ -77,15 +77,7 @@\n         if namespace in LEGACY_MINDTOUCH_NAMESPACES:\n             return mindtouch_namespace_to_kuma_url(locale, namespace, slug)\n \n-    # Last attempt: we try the request locale as the document locale,\n-    # and see if that matches something.\n-    try:\n-        doc = Document.objects.get(slug=path, locale=locale)\n-    except Document.DoesNotExist:\n-        return None\n-\n-    location = doc.get_absolute_url()\n-    return location\n+    return None\n \n \n @shared_cache_control(s_maxage=60 * 60 * 24 * 30)\n", "issue": "Wrong redirect on localized home page\nExamples:\r\n```\r\n\u25b6 curl -I https:/developer.mozilla.org/fr\r\nHTTP/2 301\r\nlocation: /fr/docs/fr\r\nserver: gunicorn/20.0.4\r\n```\r\nThe exact same is happening to `ja`\r\n\r\nBut other locales seem fine, e.g.\r\n```\r\n\u25b6 curl -I https:/developer.mozilla.org/de\r\nHTTP/2 301\r\nlocation: /de/\r\nserver: gunicorn/20.0.4\r\n```\r\nThe exact same is happening to `sv-SE` and `en-US`. \n", "before_files": [{"content": "from django.conf import settings\nfrom django.http import Http404\nfrom django.shortcuts import redirect\n\nfrom kuma.core.decorators import shared_cache_control\n\nfrom ..constants import LEGACY_MINDTOUCH_NAMESPACES\nfrom ..models import Document, Revision\n\n\n# Legacy MindTouch redirects.\n\n\ndef mindtouch_namespace_to_kuma_url(locale, namespace, slug):\n    \"\"\"\n    Convert MindTouch namespace URLs to Kuma URLs.\n\n    For special namespaces like Talk:, User:, etc., convert to the\n    approproate new URL, converting MT locales to Kuma locales.\n    If the locale cannot be correctly determined, fall back to en-US\n    \"\"\"\n    new_locale = new_slug = None\n    if namespace in (\"Talk\", \"Project\", \"Project_talk\"):\n        # These namespaces carry the old locale in their URL, which\n        # simplifies figuring out where to send them.\n        mt_locale, _, doc_slug = slug.partition(\"/\")\n        new_locale = settings.MT_TO_KUMA_LOCALE_MAP.get(mt_locale, \"en-US\")\n        new_slug = \"%s:%s\" % (namespace, doc_slug)\n    elif namespace == \"User\":\n        # For users, we look up the latest revision and get the locale\n        # from there.\n        new_slug = \"%s:%s\" % (namespace, slug)\n        try:\n            # TODO: Tests do not include a matching revision\n            rev = Revision.objects.filter(document__slug=new_slug).latest(\"created\")\n            new_locale = rev.document.locale\n        except Revision.DoesNotExist:\n            # If that doesn't work, bail out to en-US.\n            new_locale = \"en-US\"\n    else:\n        # Templates, etc. don't actually have a locale, so we give\n        # them the default.\n        new_locale = \"en-US\"\n        new_slug = \"%s:%s\" % (namespace, slug)\n    if new_locale:\n        # TODO: new_locale is unused, no alternate branch\n        new_url = \"/%s/docs/%s\" % (locale, new_slug)\n    return new_url\n\n\ndef mindtouch_to_kuma_url(locale, path):\n    \"\"\"\n    Convert valid MindTouch namespace URLs to Kuma URLs.\n\n    If there is an appropriate Kuma URL, then it is returned.\n    If there is no appropriate Kuma URL, then None is returned.\n    \"\"\"\n    if path.startswith(\"%s/\" % locale):\n        # Convert from Django-based LocaleMiddleware path to zamboni/amo style\n        path = path.replace(\"%s/\" % locale, \"\", 1)\n\n    if path.startswith(\"Template:MindTouch\"):\n        # MindTouch's default templates. There shouldn't be links to\n        # them anywhere in the wild, but just in case we 404 them.\n        # TODO: Tests don't exercise this branch\n        return None\n\n    if path.endswith(\"/\"):\n        # If there's a trailing slash, snip it off.\n        path = path[:-1]\n\n    if \":\" in path:\n        namespace, _, slug = path.partition(\":\")\n        # The namespaces (Talk:, User:, etc.) get their own\n        # special-case handling.\n        # TODO: Test invalid namespace\n        if namespace in LEGACY_MINDTOUCH_NAMESPACES:\n            return mindtouch_namespace_to_kuma_url(locale, namespace, slug)\n\n    # Last attempt: we try the request locale as the document locale,\n    # and see if that matches something.\n    try:\n        doc = Document.objects.get(slug=path, locale=locale)\n    except Document.DoesNotExist:\n        return None\n\n    location = doc.get_absolute_url()\n    return location\n\n\n@shared_cache_control(s_maxage=60 * 60 * 24 * 30)\ndef mindtouch_to_kuma_redirect(request, path):\n    \"\"\"\n    Given a request to a Mindtouch-generated URL, generate a redirect\n    to the correct corresponding kuma URL.\n\n    TODO: Retire this catch-all view and Mindtouch redirects.\n    Safest: Ensure no current content includes these URLs, no incoming links.\n    Middle: Monitor 404s and their referrer headers, fix links after removal.\n    Fastest: Remove it, ignore 404s.\n    \"\"\"\n    locale = request.LANGUAGE_CODE\n    url = mindtouch_to_kuma_url(locale, path)\n    if url:\n        if \"view\" in request.GET:\n            url = \"%s$%s\" % (url, request.GET[\"view\"])\n        return redirect(url, permanent=True)\n    else:\n        raise Http404\n", "path": "kuma/wiki/views/legacy.py"}], "after_files": [{"content": "from django.conf import settings\nfrom django.http import Http404\nfrom django.shortcuts import redirect\n\nfrom kuma.core.decorators import shared_cache_control\n\nfrom ..constants import LEGACY_MINDTOUCH_NAMESPACES\nfrom ..models import Revision\n\n\n# Legacy MindTouch redirects.\n\n\ndef mindtouch_namespace_to_kuma_url(locale, namespace, slug):\n    \"\"\"\n    Convert MindTouch namespace URLs to Kuma URLs.\n\n    For special namespaces like Talk:, User:, etc., convert to the\n    approproate new URL, converting MT locales to Kuma locales.\n    If the locale cannot be correctly determined, fall back to en-US\n    \"\"\"\n    new_locale = new_slug = None\n    if namespace in (\"Talk\", \"Project\", \"Project_talk\"):\n        # These namespaces carry the old locale in their URL, which\n        # simplifies figuring out where to send them.\n        mt_locale, _, doc_slug = slug.partition(\"/\")\n        new_locale = settings.MT_TO_KUMA_LOCALE_MAP.get(mt_locale, \"en-US\")\n        new_slug = \"%s:%s\" % (namespace, doc_slug)\n    elif namespace == \"User\":\n        # For users, we look up the latest revision and get the locale\n        # from there.\n        new_slug = \"%s:%s\" % (namespace, slug)\n        try:\n            # TODO: Tests do not include a matching revision\n            rev = Revision.objects.filter(document__slug=new_slug).latest(\"created\")\n            new_locale = rev.document.locale\n        except Revision.DoesNotExist:\n            # If that doesn't work, bail out to en-US.\n            new_locale = \"en-US\"\n    else:\n        # Templates, etc. don't actually have a locale, so we give\n        # them the default.\n        new_locale = \"en-US\"\n        new_slug = \"%s:%s\" % (namespace, slug)\n    if new_locale:\n        # TODO: new_locale is unused, no alternate branch\n        new_url = \"/%s/docs/%s\" % (locale, new_slug)\n    return new_url\n\n\ndef mindtouch_to_kuma_url(locale, path):\n    \"\"\"\n    Convert valid MindTouch namespace URLs to Kuma URLs.\n\n    If there is an appropriate Kuma URL, then it is returned.\n    If there is no appropriate Kuma URL, then None is returned.\n    \"\"\"\n    if path.startswith(\"%s/\" % locale):\n        # Convert from Django-based LocaleMiddleware path to zamboni/amo style\n        path = path.replace(\"%s/\" % locale, \"\", 1)\n\n    if path.startswith(\"Template:MindTouch\"):\n        # MindTouch's default templates. There shouldn't be links to\n        # them anywhere in the wild, but just in case we 404 them.\n        # TODO: Tests don't exercise this branch\n        return None\n\n    if path.endswith(\"/\"):\n        # If there's a trailing slash, snip it off.\n        path = path[:-1]\n\n    if \":\" in path:\n        namespace, _, slug = path.partition(\":\")\n        # The namespaces (Talk:, User:, etc.) get their own\n        # special-case handling.\n        # TODO: Test invalid namespace\n        if namespace in LEGACY_MINDTOUCH_NAMESPACES:\n            return mindtouch_namespace_to_kuma_url(locale, namespace, slug)\n\n    return None\n\n\n@shared_cache_control(s_maxage=60 * 60 * 24 * 30)\ndef mindtouch_to_kuma_redirect(request, path):\n    \"\"\"\n    Given a request to a Mindtouch-generated URL, generate a redirect\n    to the correct corresponding kuma URL.\n\n    TODO: Retire this catch-all view and Mindtouch redirects.\n    Safest: Ensure no current content includes these URLs, no incoming links.\n    Middle: Monitor 404s and their referrer headers, fix links after removal.\n    Fastest: Remove it, ignore 404s.\n    \"\"\"\n    locale = request.LANGUAGE_CODE\n    url = mindtouch_to_kuma_url(locale, path)\n    if url:\n        if \"view\" in request.GET:\n            url = \"%s$%s\" % (url, request.GET[\"view\"])\n        return redirect(url, permanent=True)\n    else:\n        raise Http404\n", "path": "kuma/wiki/views/legacy.py"}]}