所以我想在我的服务器上使用尾随斜杠,id就像用户能够同时转到example / oreo和example / oreo /
到目前为止,这是我的.htaccess看起来像
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# To externally redirect /dir/foo.html to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.html
RewriteCond %{REQUEST_FILENAME}.html -f [NC]
RewriteRule ^ %{REQUEST_URI}.html [L]
答案 0 :(得分:0)
尝试更改此规则:
RewriteCond %{REQUEST_FILENAME}.html -f [NC]
RewriteRule ^ %{REQUEST_URI}.html [L]
为:
RewriteCond %{DOCUMENT_ROOT}/$1.html -f [NC]
RewriteRule ^(.*?)/?$ /$1.html [L]
这样就可以从捕获组中排除尾部斜杠,并且可以在条件和目标中反向引用斜杠。