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_domaintoINSTALLED_APPSandcanonical_domain.middleware.canonical_domainto yourMIDDLEWAREsetting. Ensure that you add this middleware beforedjango.middleware.security.SecurityMiddleware. - Set
SECURE_SSL_HOST = 'example.com'in your settings. - Optionally set
SECURE_SSL_REDIRECT = Trueif you want to enforce HTTPS.
Change log¶
Next version¶
- Added the requirement that
canonical_domainbe added toINSTALLED_APPSbecause otherwise the system checks wouldn’t run at all. - Added deploy checks which verify that
SECURE_SSL_HOSTandSECURE_SSL_REDIRECThave 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_REDIRECTandSECURE_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
CanonicalDomainMiddlewarewith a new function-basedcanonical_domainmiddleware which does not extendSecurityMiddleware. You should addSecurityMiddlewareyourself 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,OPTIONSandTRACE).