From 28b8326003fa10637f6b4136df05338f7a352a80 Mon Sep 17 00:00:00 2001 From: fechin Date: Fri, 10 Mar 2023 09:27:23 +0800 Subject: [PATCH] Update nginx rewrite rules for removing .html extension --- nginx.conf | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/nginx.conf b/nginx.conf index f0f92c4..c1d60b2 100644 --- a/nginx.conf +++ b/nginx.conf @@ -35,12 +35,14 @@ http { # Rename cheatsheet rewrite ^/golang$ /go permanent; - # remove .html extension location / { - if ($request_uri ~ ^/(.*)\.html) { - return 302 /$1; - } - try_files $uri $uri.html $uri/ =404; + try_files $uri $uri/ @html; + } + + location @html { + # remove .html extension + rewrite ^(.*)\.html$ $1 permanent; + try_files $uri.html $uri/ =404; } } }