prod: redirect apex mandelblog.com to www

This commit is contained in:
2026-05-03 02:16:51 +02:00
parent 856f7333d4
commit 556faacc78
2 changed files with 28 additions and 0 deletions

View 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)

View File

@@ -116,6 +116,10 @@ if "django.middleware.locale.LocaleMiddleware" not in MIDDLEWARE:
else:
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"
LANGUAGES = [
("nl", "Nederlands"),