Apache 服务器加载页面而不是应用重写规则

Apache server loads page instead of applying rewrite rule

我试图让我的网站添加尾部斜杠,然后将 URI 重写为 html 页面。基本上重定向 xy.com/abcxy.com/abc/,然后实际加载 xy.com/abc.html.

我的 .htaccess 文件如下所示:

RewriteEngine on
RewriteBase /
RewriteRule ^([a-z]+)$ / [R]
RewriteRule ^([a-z]+)/$ .html [L]

当我尝试转到 xy.com/asd(不存在的页面)时,它会重定向到 xy.com/asd/ 并给我正确的 404 错误。

当我尝试使用实际存在的页面 (xy.com/about) 时,它只是加载 xy.com/about.html 而根本没有重定向。

试试这个代码:

Options -MultiViews
RewriteEngine on
RewriteBase /

RewriteRule ^([a-z]+)$ / [R,NC,L]

RewriteCond %{DOCUMENT_ROOT}/.html -f
RewriteRule ^([a-z]+)/$ .html [L,NC]