Changeset - 5fa226284bcb
[Not reviewed]
1 7 0
Ben Sturmfels (bsturmfels) - 2 months ago 2024-03-20 03:54:54
ben@sturm.com.au
Delegate management of canonical URLs to Apache

This middleware is mostly redundant:

* redirecting to canonical URLs can be done more simply in Apache
* appending a forward slash is a default in CommonMiddleware now
* we're no longer using Squid cache

May need to update Apache to strip/redirect trailing "index.html".
8 files changed with 4 insertions and 85 deletions:
0 comments (0 inline, 0 general)
TODO.md
Show inline comments
...
 
@@ -2,3 +2,3 @@
 

	
 
* remove `ForceCanonicalHostnameMiddleware` by ensuring canonical redirect and HTTPS redirect is done by Apache
 
* ask Denver about why so many license files
 
* serve a 400 in Apache for a hostname we don't explicitly support
...
 
@@ -11,2 +11,3 @@
 

	
 
* remove `ForceCanonicalHostnameMiddleware` by ensuring canonical redirect and HTTPS redirect is done by Apache
 
* standardise settings to replace `settings.py` and `djangocommonsettings.py`
conservancy/blog/views.py
Show inline comments
...
 
@@ -116,7 +116,4 @@ def relative_redirect(request, path):
 
    from django import http
 
    from django.conf import settings
 

	
 
    host = request.get_host()
 
    if settings.FORCE_CANONICAL_HOSTNAME:
 
        host = settings.FORCE_CANONICAL_HOSTNAME
 

	
conservancy/local_context_processors.py
Show inline comments
...
 
@@ -2,4 +2,2 @@ from datetime import datetime as DateTime
 

	
 
from django.conf import settings
 

	
 
from .fundgoal.models import FundraisingGoal
...
 
@@ -21,8 +19,3 @@ def sitefundraiser(request):
 

	
 
if settings.FORCE_CANONICAL_HOSTNAME:
 
    _HOST_URL_VAR = {'host_url': 'https://' + settings.FORCE_CANONICAL_HOSTNAME}
 
    def host_url(request):
 
        return _HOST_URL_VAR
 
else:
 
    def host_url(request):
 
        return {'host_url': request.build_absolute_uri('/').rstrip('/')}
 
def host_url(request):
 
    return {'host_url': request.build_absolute_uri('/').rstrip('/')}
conservancy/middleware.py
Show inline comments
 
deleted file
conservancy/podjango/views.py
Show inline comments
...
 
@@ -107,7 +107,4 @@ def relative_redirect(request, path):
 
    from django import http
 
    from django.conf import settings
 

	
 
    host = http.get_host(request)
 
    if settings.FORCE_CANONICAL_HOSTNAME:
 
        host = settings.FORCE_CANONICAL_HOSTNAME
 

	
conservancy/settings/base.py
Show inline comments
...
 
@@ -24,6 +24,2 @@ ROOT_URLCONF = 'conservancy.urls'
 

	
 
REDIRECT_TABLE = {
 
    'www.sf-conservancy.org': 'sfconservancy.org',
 
}
 

	
 
LOGGING = {
...
 
@@ -138,3 +134,2 @@ MIDDLEWARE = [
 
    'django.contrib.messages.middleware.MessageMiddleware',
 
    'conservancy.middleware.ForceCanonicalHostnameMiddleware',
 
]
conservancy/settings/dev.py
Show inline comments
...
 
@@ -5,4 +5,2 @@ ALLOWED_HOSTS = ['*']
 

	
 
FORCE_CANONICAL_HOSTNAME = False
 

	
 
DATABASES = {
conservancy/settings/prod.py
Show inline comments
...
 
@@ -9,4 +9,2 @@ ALLOWED_HOSTS = ['www.sfconservancy.org', 'sfconservancy.org']
 

	
 
FORCE_CANONICAL_HOSTNAME = 'sfconservancy.org'
 

	
 
ADMINS = [
0 comments (0 inline, 0 general)