django-canonical-domain - Canonical domain redirection for Django¶
Version 0.9.2
This module allows redirecting all requests for a given Django instance to a single canonical domain and optionally enforcing HTTPS for all requests as well.
Installation and usage¶
pip install django-canonical-domain
- Add
canonical_domain
toINSTALLED_APPS
andcanonical_domain.middleware.canonical_domain
to yourMIDDLEWARE
setting. Ensure that you add this middleware beforedjango.middleware.security.SecurityMiddleware
. - Set
SECURE_SSL_HOST = 'example.com'
in your settings. - Optionally set
SECURE_SSL_REDIRECT = True
if you want to enforce HTTPS.
Change log¶
Next version¶
- Added the requirement that
canonical_domain
be added toINSTALLED_APPS
because otherwise the system checks wouldn’t run at all. - Added deploy checks which verify that
SECURE_SSL_HOST
andSECURE_SSL_REDIRECT
have been set.
0.9 (2022-01-31)¶
- Added pre-commit.
- Dropped support for Django < 3.2, Python < 3.8, added support for Django 4.0 and Python 3.10.
- Switched back to using
SECURE_SSL_REDIRECT
andSECURE_SSL_HOST
– introducing our own settings made it necessary to silence Django’s system checks for them. Let’s not do that anymore. Added system checks to ensure that the new settings are added correctly. - Added a system check which verifies that the canonical domain middleware
appears before the security middleware in
MIDDLEWARE
.
0.4 (2021-07-20)¶
- Dropped official support for Django < 2.2 and Python < 3.6.
- Switched to a declarative setup.
- Switched to GitHub actions.
- Replaced the
CanonicalDomainMiddleware
with a new function-basedcanonical_domain
middleware which does not extendSecurityMiddleware
. You should addSecurityMiddleware
yourself and remove the silencing ofsecurity.W001
.
0.3 (2018-12-24)¶
- Removed the self-deactivation of the middleware when
DEBUG = True
. - Reformatted the code using black.
- Changed the middleware to only redirect safe methods (
GET
,HEAD
,OPTIONS
andTRACE
).