prod: redirect apex mandelblog.com to www
This commit is contained in:
24
mandelstudio/middleware.py
Normal file
24
mandelstudio/middleware.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from django.http import HttpRequest, HttpResponsePermanentRedirect
|
||||||
|
|
||||||
|
|
||||||
|
class RedirectApexToWwwMiddleware:
|
||||||
|
"""Redirect `mandelblog.com` to `www.mandelblog.com` for production.
|
||||||
|
|
||||||
|
We keep this project-scoped and host-specific so staging hostnames and other
|
||||||
|
Mandel environments are unaffected.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, get_response):
|
||||||
|
self.get_response = get_response
|
||||||
|
|
||||||
|
def __call__(self, request: HttpRequest):
|
||||||
|
host = (request.get_host() or "").split(":")[0].lower()
|
||||||
|
if host == "mandelblog.com":
|
||||||
|
destination = request.build_absolute_uri().replace(
|
||||||
|
"://mandelblog.com", "://www.mandelblog.com", 1
|
||||||
|
)
|
||||||
|
return HttpResponsePermanentRedirect(destination)
|
||||||
|
return self.get_response(request)
|
||||||
|
|
||||||
@@ -116,6 +116,10 @@ if "django.middleware.locale.LocaleMiddleware" not in MIDDLEWARE:
|
|||||||
else:
|
else:
|
||||||
MIDDLEWARE.insert(0, "django.middleware.locale.LocaleMiddleware")
|
MIDDLEWARE.insert(0, "django.middleware.locale.LocaleMiddleware")
|
||||||
|
|
||||||
|
# Redirect production apex to `www` for a single canonical domain.
|
||||||
|
if "mandelstudio.middleware.RedirectApexToWwwMiddleware" not in MIDDLEWARE:
|
||||||
|
MIDDLEWARE.insert(0, "mandelstudio.middleware.RedirectApexToWwwMiddleware")
|
||||||
|
|
||||||
LANGUAGE_CODE = "nl"
|
LANGUAGE_CODE = "nl"
|
||||||
LANGUAGES = [
|
LANGUAGES = [
|
||||||
("nl", "Nederlands"),
|
("nl", "Nederlands"),
|
||||||
|
|||||||
Reference in New Issue
Block a user