Skip to content
Middleware to redirect requests to a canonical host
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Build Status pypi release

Sometimes, it's unavoidable that multiple URLs point at the same app - for example, on Heroku, all apps get a address, as well as any custom domains that are pointed at them.

This is a simple Django middleware that redirects all traffic from hosts other than the one(s) you specify to your canonical URL.

Tested against Django 1.8, 1.9, 1.10, 1.11 on Python 2.7, 3.4 and 3.6


Install from PIP

pip install django-enforce-host

In your MIDDLEWARE setting, add the following at the top:

    ... other middleware

Set the following setting to be either a single allowed host, or a list of allowed hosts:


That's it!

Code of conduct

For guidelines regarding the code of conduct when contributing to this repository please review

You can’t perform that action at this time.