Code

Ticket #2112: strip_www.diff

File strip_www.diff, 1.3 KB (added by pa-ching, 8 years ago)
Line 
1Index: django/conf/global_settings.py
2===================================================================
3--- django/conf/global_settings.py      (revision 3103)
4+++ django/conf/global_settings.py      (working copy)
5@@ -148,6 +148,9 @@
6 # Whether to prepend the "www." subdomain to URLs that don't have it.
7 PREPEND_WWW = False
8 
9+# Alternatively, whether to strip the "www." subdomain from URLs that have it.
10+STRIP_WWW = False
11+
12 # List of compiled regular expression objects representing User-Agent strings
13 # that are not allowed to visit any page, systemwide. Use this for bad
14 # robots/crawlers. Here are a few examples:
15Index: django/middleware/common.py
16===================================================================
17--- django/middleware/common.py (revision 3103)
18+++ django/middleware/common.py (working copy)
19@@ -35,6 +35,8 @@
20         new_url = old_url[:]
21         if settings.PREPEND_WWW and old_url[0] and not old_url[0].startswith('www.'):
22             new_url[0] = 'www.' + old_url[0]
23+        elif settings.STRIP_WWW and old_url[0] and old_url[0].startswith('www.'):
24+            new_url[0] = old_url[4:]
25         # Append a slash if append_slash is set and the URL doesn't have a
26         # trailing slash or a file extension.
27         if settings.APPEND_SLASH and (old_url[1][-1] != '/') and ('.' not in old_url[1].split('/')[-1]):