重定向 .html 和尾部斜杠

Redirect .html and trailing slash

我的网站的 .htaccess 文件有点问题。我想让 page.html 和 page/ URLs 都重定向到没有任何后缀的页面。我已经能够关闭 .html,但是当进入页面/URL 时,无论我尝试什么(Apache 2.4.18),我都会收到内部服务器错误。

这是完整的 .htaccess 代码(没有尝试删除结尾的斜杠)

Options +FollowSymLinks -Indexes -MultiViews

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^website\.com$ [NC]
RewriteRule ^(.*)$ http://www.website.com/ [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.website.com/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ .html [L,QSA]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule ^(.*)\.html$ / [R=301,L]

我想做的只是复制适用于 .html 的最后 6 行,但让它作用于尾部斜线,但我不确定该怎么做,或者是否有更好的解决方案。非常感谢任何建议!

你试过

(\.html|\/)

我现在不在 mac 上,但您可以使用 or 运算符来完成。

使用多个网址在 https://regex101.com/ 上查看。

要删除结尾的斜杠,请执行以下操作:

RewriteEngine on
RewriteRule (.+)/$ /example/ [L,R=301]

删除多余的斜线:

RewriteCond %{THE_REQUEST} //
RewriteRule .* [=11=] [R]