Skip to content

Instantly share code, notes, and snippets.

@bootandy
Forked from dryan/remove_www_middleware.py
Last active December 23, 2015 01:49
Show Gist options
  • Save bootandy/6563355 to your computer and use it in GitHub Desktop.
Save bootandy/6563355 to your computer and use it in GitHub Desktop.
class RemoveWWW(object):
def process_request( self, request ):
try:
if request.META['HTTP_HOST'].lower().find('www.') == 0:
from django.http import HttpResponsePermanentRedirect
return HttpResponsePermanentRedirect( request.build_absolute_uri().replace('//www.', '//') )
except:
pass
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment