Skip to content
Middleware to redirect requests to a canonical host
Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
enforce_host
.gitignore
.travis.yml
LICENSE
README.md
manage.py
setup.py

README.md

django-enforce-host

Build Status pypi release

Sometimes, it's unavoidable that multiple URLs point at the same app - for example, on Heroku, all apps get a .herokuapp.com 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

Installation

Install from PIP

pip install django-enforce-host

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

MIDDLEWARE = [
    'enforce_host.EnforceHostMiddleware',
    ... other middleware
]

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

ENFORCE_HOST = 'yourapp.com'

That's it!

Code of conduct

For guidelines regarding the code of conduct when contributing to this repository please review https://www.dabapps.com/open-source/code-of-conduct/

You can’t perform that action at this time.