【发布时间】:2021-12-24 04:28:27
【问题描述】:
我希望在使用 htaccess 给出斜杠时删除斜杠。符合我现有规则的最佳方法是什么:
# make sure www. is always there
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# if requested url does not exist pass it as path info to index.php
RewriteRule ^$ index.php?/ [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?/$1 [QSA,L]
示例 URL 类似于:
https://www.example.com/this-test/
我当然希望去掉结尾的斜线。
我试过了:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R,L]
但这不适用于现有的规则。由于其他规则,它最终会重定向到 index.php 页面。
【问题讨论】:
-
感谢您在问题中分享您的努力,请务必提及您在问题中点击的示例网址。
-
添加了更多信息。
-
您尝试在现有规则的哪个位置插入新规则?
-
我在任何位置都试过了,但都无法正常工作。
标签: .htaccess url mod-rewrite trailing-slash