【问题标题】:How to remove slash from url using htaccess [duplicate]如何使用 htaccess 从 url 中删除斜杠 [重复]
【发布时间】:2017-09-08 10:39:00
【问题描述】:

我正在使用 htaccess 重写 url。
这是我的 .htaccess 文件

Options -Indexes
RewriteEngine on

RewriteRule (.*)/$ post.php?&url=$1

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]

我想从网址末尾删除斜杠。
例如:

https://www.example.com/some-post/


https://www.example.com/some-post

PS。不是来自 index.php,而是来自不同的页面。

【问题讨论】:

    标签: php regex .htaccess mod-rewrite


    【解决方案1】:

    要强制从以 / 结尾的 URL 重定向到不带斜杠的相同 URL,只需执行以下操作:

    RewriteRule ^(.+)/$ $1 [L,R=301,QSA]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-12
      • 2013-04-14
      • 2014-08-14
      • 2021-02-06
      相关资源
      最近更新 更多