0

删除html扩展后如何使用以下代码在末尾添加/:

Options +FollowSymLinks -MultiViews
DirectorySlash off

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME}/ -d
RewriteCond %{SCRIPT_FILENAME}.html !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.+)\.html$ /$1 [R=301,L]

RewriteCond %{SCRIPT_FILENAME}.html -f
RewriteRule [^/]$ %{REQUEST_URI}.html [QSA,L]
4

1 回答 1

0

您将需要进行一些更改。

Options +FollowSymLinks -MultiViews

RewriteEngine On    
RewriteBase /

#Code to add forward slash
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !(?:\.\w+|/)$
RewriteRule (.*) $1/ [R,L]

#To check whether a .html appended string is a file existing on the system 
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule (.*)/ $1.html [L]

#### NOT REQUIRED
#RewriteCond %{SCRIPT_FILENAME}/ -d
#RewriteCond %{SCRIPT_FILENAME}.html !-f
#RewriteRule [^/]$ %{REQUEST_URI}/ [R,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.+)\.html$ /$1 [R,L]

这些规则也不会按预期工作:

RewriteCond %{SCRIPT_FILENAME}.html -f
RewriteRule [^/]+/$ %{REQUEST_URI}.html [QSA,L]

cos,%{REQUEST_URI}总会有/最后的。domain.com/about如果请求类似 URI ,

它将被重写为:

domain.com/about/

最后到

domain.com/about/.html
于 2012-02-29T14:01:43.363 回答