kopia lustrzana https://github.com/wagtail/wagtail
Issue #647
Update redirect middleware to try old_path without query string if we can't find a redirect for old_path with query stringpull/1692/head
rodzic
ca92f5ede0
commit
aa80e61bef
|
@ -1,4 +1,5 @@
|
||||||
from django import http
|
from django import http
|
||||||
|
from django.utils.six.moves.urllib.parse import urlparse
|
||||||
|
|
||||||
from wagtail.wagtailredirects import models
|
from wagtail.wagtailredirects import models
|
||||||
|
|
||||||
|
@ -12,13 +13,16 @@ class RedirectMiddleware(object):
|
||||||
|
|
||||||
# Get the path
|
# Get the path
|
||||||
path = models.Redirect.normalise_path(request.get_full_path())
|
path = models.Redirect.normalise_path(request.get_full_path())
|
||||||
|
path_without_query = urlparse(path)[2]
|
||||||
|
|
||||||
# Find redirect
|
# Find redirect
|
||||||
try:
|
try:
|
||||||
redirect = models.Redirect.get_for_site(request.site).get(old_path=path)
|
redirect = models.Redirect.get_for_site(request.site).get(old_path=path)
|
||||||
except models.Redirect.DoesNotExist:
|
except models.Redirect.DoesNotExist:
|
||||||
# No redirect found, return the 400 page
|
try:
|
||||||
return response
|
redirect = models.Redirect.get_for_site(request.site).get(old_path=path_without_query)
|
||||||
|
except models.Redirect.DoesNotExist:
|
||||||
|
return response
|
||||||
|
|
||||||
if redirect.is_permanent:
|
if redirect.is_permanent:
|
||||||
return http.HttpResponsePermanentRedirect(redirect.link)
|
return http.HttpResponsePermanentRedirect(redirect.link)
|
||||||
|
|
Ładowanie…
Reference in New Issue