Add middleware that catches 404 errors if the original URL has a trailing

period and redirects to the same URL with no trailing periods.
Add a redirect test in the top-level testurl.list.
 - Legacy-Id: 850
This commit is contained in:
Bill Fenner 2007-07-07 19:26:18 +00:00
parent d7a4617d2a
commit 60cd431e2f
3 changed files with 9 additions and 0 deletions

View file

@ -8,6 +8,7 @@ except ImportError:
from django.db import connection
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.http import HttpResponsePermanentRedirect
from ietf.utils import log
import re
import smtplib
@ -61,3 +62,9 @@ class SMTPExceptionMiddleware(object):
return render_to_response('email_failed.html', {'exception': type, 'args': value, 'traceback': "".join(tb)},
context_instance=RequestContext(request))
return None
class RedirectTrailingPeriod(object):
def process_response(self, request, response):
if response.status_code == 404 and request.path.endswith("."):
return HttpResponsePermanentRedirect(request.path.rstrip("."))
return response

View file

@ -90,6 +90,7 @@ MIDDLEWARE_CLASSES = (
# 'ietf.middleware.PrettifyMiddleware',
'ietf.middleware.SQLLogMiddleware',
'ietf.middleware.SMTPExceptionMiddleware',
'ietf.middleware.RedirectTrailingPeriod',
'django.middleware.transaction.TransactionMiddleware',
)

View file

@ -7,3 +7,4 @@ skip /css/base.css
skip /js/
200 /googlea30ad1dacffb5e5b.html # Google webmaster tool verification page
301 /list/request.... # test middleware that strips periods and redirects instead of 404