1 2 3 4 5 6 7 8 9 10 11 12 13 14 | from django.conf import settings
from django.http import HttpResponsePermanentRedirect
class PermanentRedirectMiddleware(object):
def process_request(self, request):
if hasattr(settings, 'HTTP_HOST_DOMAIN') and\
'HTTP_HOST' in request.META and \
request.META['HTTP_HOST'] != settings.HTTP_HOST_DOMAIN:
return HttpResponsePermanentRedirect("http%s://%s%s"%(
request.is_secure() and 's' or '',
settings.HTTP_HOST_DOMAIN,
request.get_full_path(),
)
)
|
Comments
Here is something better for you which even works with http/https:
class ForceDomainMiddleware(object):
#
Fixed with mk good ideas :)
#