From aa80e61befc2219a1dff8a8dbff60917f2d03403 Mon Sep 17 00:00:00 2001 From: Michael Cordover Date: Sat, 12 Sep 2015 22:33:26 +1000 Subject: [PATCH] Issue #647 Update redirect middleware to try old_path without query string if we can't find a redirect for old_path with query string --- wagtail/wagtailredirects/middleware.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/wagtail/wagtailredirects/middleware.py b/wagtail/wagtailredirects/middleware.py index 7ce094a358..b3ef32c5e5 100644 --- a/wagtail/wagtailredirects/middleware.py +++ b/wagtail/wagtailredirects/middleware.py @@ -1,4 +1,5 @@ from django import http +from django.utils.six.moves.urllib.parse import urlparse from wagtail.wagtailredirects import models @@ -12,13 +13,16 @@ class RedirectMiddleware(object): # Get the path path = models.Redirect.normalise_path(request.get_full_path()) + path_without_query = urlparse(path)[2] # Find redirect try: redirect = models.Redirect.get_for_site(request.site).get(old_path=path) except models.Redirect.DoesNotExist: - # No redirect found, return the 400 page - return response + try: + redirect = models.Redirect.get_for_site(request.site).get(old_path=path_without_query) + except models.Redirect.DoesNotExist: + return response if redirect.is_permanent: return http.HttpResponsePermanentRedirect(redirect.link)