diff options
| author | alex <alex@pdp7.net> | 2023-10-22 16:53:40 +0200 |
|---|---|---|
| committer | alex <alex@pdp7.net> | 2023-10-22 16:53:40 +0200 |
| commit | a37ff9f671fc4f3179c821c9be73a702e25ec4ce (patch) | |
| tree | e611a0d86b5b128d826f8e351f788a0658fe0261 | |
| parent | 3684c430033db100e0b1a43be143399d529dd432 (diff) | |
Redirect URLs not ending in /
| -rw-r--r-- | blog/blog/__init__.py | 4 | ||||
| -rw-r--r-- | blog/poetry.lock | 2 |
2 files changed, 4 insertions, 2 deletions
diff --git a/blog/blog/__init__.py b/blog/blog/__init__.py index 81332ddd..03ca923f 100644 --- a/blog/blog/__init__.py +++ b/blog/blog/__init__.py @@ -36,6 +36,8 @@ class SimplePage(page.BasePage): def handler(request: bicephalus.Request) -> bicephalus.Response: + if not request.path.endswith("/"): + return bicephalus.Response(request.path + "/", None, bicephalus.Status.PERMANENT_REDIRECTION) if request.path == "/": return blog_pages.Root(request).response() if re.match(r"/\d{4}/\d{2}/.*/", request.path): @@ -48,7 +50,7 @@ def handler(request: bicephalus.Request) -> bicephalus.Response: return SimplePage(request, request.path, "About Álex Córcoles").response() if request.path == "/laspelis/": return SimplePage(request, request.path, "laspelis").response() - if re.match(r"/laspelis/\d+/?", request.path): + if re.match(r"/laspelis/\d+/", request.path): return SimplePage(request, request.path.removesuffix("/") + "/", request.path).response() return page.NotFound(request).response() diff --git a/blog/poetry.lock b/blog/poetry.lock index 57ce657d..8d11fb28 100644 --- a/blog/poetry.lock +++ b/blog/poetry.lock @@ -235,7 +235,7 @@ opentelemetry-sdk = "^1.20.0" type = "git" url = "https://github.com/alexpdp7/bicephalus.git" reference = "HEAD" -resolved_reference = "ca0c7e85d9f6926a08040fc492a31e5b129defa0" +resolved_reference = "3558c6e0c86e646a8f0fb214e5dce9126497a73b" [[package]] name = "charset-normalizer" |
