remove.html,并允许在url末尾使用和不使用尾部斜杠



我想使用.htaccess删除URL中的.html扩展名,并能够访问末尾带有或不带有斜杠的URL。现在,当我调用末尾带有斜线的页面时,我会得到一个500内部服务器错误

我的.htaccess代码:

DirectorySlash Off
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}s([^.]+).html [NC]
RewriteRule ^ %1 [R,L,NC]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [L]

这样做:

DirectorySlash Off
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
# To externally redirect /dir/file.html to /dir/file
RewriteCond %{THE_REQUEST} s/+(.+?).html[s?] [NC]
RewriteRule ^ /%1 [R=302,NE,L]
# To internally forward /dir/file to /dir/file.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^(.+?)/?$ $1.php [L]

一些Apache实现在解析%{REQUEST_FILENAME}时可能存在错误,因此最好使用%{DOCUMENT_ROOT}构建完整的文件路径。

最新更新