catch trailing slash when redirecting
This commit is contained in:
parent
c93d55dacc
commit
35fa7715a8
3 changed files with 13 additions and 2 deletions
2
Makefile
2
Makefile
|
@ -1,5 +1,5 @@
|
|||
.PHONY: help build publish
|
||||
VERSION = 1.1.2
|
||||
VERSION = 1.1.3
|
||||
|
||||
help:
|
||||
@perl -nle'print $& if m{^[a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
||||
|
|
|
@ -24,5 +24,16 @@ class BlogRedirectMiddleware:
|
|||
except Http404:
|
||||
# If the new URL doesn't exist, return the original 404 response
|
||||
pass
|
||||
# handle old blog urls e.g. `https://www.iamkonstantin.eu/posts/safari-local-overrides/`
|
||||
# replace /posts/ with /blog/ and remove trailing /
|
||||
if response.status_code == 404 and request.path.startswith('/posts/'):
|
||||
new_path = f'/blog{request.path[6:]}'
|
||||
if new_path.endswith('/'):
|
||||
new_path = new_path[:-1]
|
||||
try:
|
||||
resolve(new_path)
|
||||
return HttpResponseRedirect(new_path)
|
||||
except Http404:
|
||||
pass
|
||||
|
||||
return response
|
||||
|
|
|
@ -2,7 +2,7 @@ version: '3.8'
|
|||
|
||||
services:
|
||||
wagtail:
|
||||
image: code.headbright.be/konstantin/iamkonstantin:1.0.6
|
||||
image: code.headbright.be/konstantin/iamkonstantin:1.1.2
|
||||
container_name: wagtail
|
||||
restart: always
|
||||
volumes:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue