Adding www middleware

master
Nick Sergeant 2011-10-23 21:18:28 -04:00
parent ea412105d0
commit 477cf2f1bb
3 changed files with 16 additions and 2 deletions

View File

14
snipt/middleware/www.py Normal file
View File

@ -0,0 +1,14 @@
import re
from django.conf import settings
from django.core import urlresolvers
from django.http import HttpResponse, HttpResponseRedirect
class WWWMiddleware(object):
def process_request(self, request):
url = request.build_absolute_uri(request.get_full_path())
if 'www.' in url:
non_www_url = url.replace('www.', '')
return HttpResponseRedirect(non_www_url)

View File

@ -49,12 +49,12 @@ USE_L10N = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = ''
MEDIA_ROOT = '/Users/Nick/Code/snipt/snipt/media/'
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = ''
MEDIA_URL = '/media/'
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files