+ A static redirect middleware. Mostly useful for hosting providers that
+ automatically setup an alternative domain for your website. You might
+ not want anyone to access the site via those possibly well-known URLs.
+ def process_request(self, request):
+ host = request.get_host().split(':')
+ # Turn off redirects when in debug mode, running unit tests, or
+ # when handling an App Engine cron job.
+ if settings.DEBUG or host == 'testserver' or \
+ not getattr(settings, 'ALLOWED_DOMAINS', None) or \
+ request.META.get('HTTP_X_APPENGINE_CRON') == 'true':
+ if host not in settings.ALLOWED_DOMAINS:
+ return HttpResponseRedirect('http://' + settings.ALLOWED_DOMAINS)
If user is authenticated we disable browser caching of pages in history.