Skip to content

Instantly share code, notes, and snippets.

@dryan
Created January 30, 2010 22:54
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dryan/290771 to your computer and use it in GitHub Desktop.
Save dryan/290771 to your computer and use it in GitHub Desktop.
Django middleware for removing www.
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