Ticket #2476: common-update.diff

File common-update.diff, 1.1 KB (added by jeff@…, 18 years ago)

Patch adding support for REMOVE_WWW

  • django/middleware/common.py

     
    2929                if user_agent_regex.search(request.META['HTTP_USER_AGENT']):
    3030                    return http.HttpResponseForbidden('<h1>Forbidden</h1>')
    3131
    32         # Check for a redirect based on settings.APPEND_SLASH and settings.PREPEND_WWW
     32        # Check for a redirect based on settings.APPEND_SLASH, settings.PREPEND_WWW, and settings.REMOVE_WWW
    3333        host = http.get_host(request)
    3434        old_url = [host, request.path]
    3535        new_url = old_url[:]
    3636        if settings.PREPEND_WWW and old_url[0] and not old_url[0].startswith('www.'):
    3737            new_url[0] = 'www.' + old_url[0]
     38        if settings.REMOVE_WWW and old_url[0] and old_url[0].startswith('www.'):
     39            new_url[0] = old_url[4:]
    3840        # Append a slash if append_slash is set and the URL doesn't have a
    3941        # trailing slash or a file extension.
    4042        if settings.APPEND_SLASH and (old_url[1][-1] != '/') and ('.' not in old_url[1].split('/')[-1]):
Back to Top