diff --git a/blog/middleware.py b/blog/middleware.py index 0f3ec20..2f2b5c0 100644 --- a/blog/middleware.py +++ b/blog/middleware.py @@ -16,6 +16,7 @@ class BlogRedirectMiddleware: if (response.status_code == 404 and not (request.path.startswith('/blog/') or request.path.startswith('/media/'))): new_path = f'/blog{request.path}' + new_path = new_path.replace('/posts/', '/') try: # Check if the new URL with /blog/ exists resolve(new_path) @@ -24,16 +25,5 @@ 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