forked from rupalkhilari/website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.py
More file actions
29 lines (26 loc) · 1008 Bytes
/
Copy pathmiddleware.py
File metadata and controls
29 lines (26 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""import re
from django.http import HttpResponsePermanentRedirect
from django.conf import settings
class HttpBaseUrlMiddleware(object):
def process_request(self, request):
host = request.META['HTTP_HOST'] #+ request.META['PATH_INFO']
print "Host is "
print host
print request.get_full_path()
for url_pattern, redirect_url in settings.URL_REDIRECTS:
regex = re.compile(url_pattern)
if regex.match(host):
return HttpResponsePermanentRedirect(redirect_url + request.get_full_path())
domain = settings.MY_HTTP_HOST_DOMAIN
print "The domain is "
print domain
if request.META['HTTP_HOST'] != domain:
target = 'http%s://%s%s' % (
#request.is_secure() and 's' or '',
''
domain,
request.get_full_path())
print "Target is "
print target
return HttpResponsePermanentRedirect(target)
"""