Redirect Multiple Domains to a Single Domain

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
from django.http import HttpResponseRedirect

class ValidateHostMiddleware(object):
    """
    In Apache's httpd.conf, you may have ServerName set to mysite.com.au along 
    with a number of aliases: mysite.com, mysite.net, my-site.com etc.

    This middleware redirects any request that isn't for mysite.com.au to that 
    domain, helping with SEO and brand recognition.
    """
    def process_request(self, request):
        if not request.META['HTTP_HOST'].endswith('mysite.com.au'):
            return HttpResponseRedirect('http://www.mysite.com.au/')

More like this

  1. URL redirects middleware by gonz 6 years, 4 months ago
  2. SSL Middleware for Webfaction by parlar 6 years, 11 months ago
  3. PermanentRedirectMiddleware by marinho 5 years, 8 months ago
  4. simple DomainsAliasMiddleware by matrix 5 years ago
  5. SiteRedirectMiddleware by jezdez 5 years, 8 months ago

Comments

(Forgotten your password?)