【问题标题】:how can i remove trailing slashes form the url如何从 url 中删除尾部斜杠
【发布时间】:2017-01-18 07:20:52
【问题描述】:

我对 URL 末尾的斜杠有疑问。我在线检查了 URL 重定向,结果显示我的页面上有太多重定向,所以我需要减少这些重定向我的链接有以下结果

https://example.com/xyz/pqr
302 Found
https://example.com/xyz/pqr/
302 Found
https://example.com/xyz/pqr//
302 Found
https://example.com/xyz/pqr///
302 Found
https://example.com/xyz/pqr////
302 Found
https://example.com/xyz/pqr/////
302 Found
https://example.com/xyz/pqr//////
302 Found
https://example.com/xyz/pqr///////
302 Found
https://example.com/xyz/pqr////////
302 Found
https://example.com/xyz/pqr/////////
302 Found
https://example.com/xyz/pqr//////////
302 Found
https://example.com/xyz/pqr///////////
302 Found
https://example.com/xyz/pqr////////////
302 Found
https://example.com/xyz/pqr/////////////
302 Found
https://example.com/xyz/pqr//////////////
302 Found
https://example.com/xyz/pqr///////////////
302 Found
https://example.com/xyz/pqr////////////////
302 Found
https://example.com/xyz/pqr/////////////////
302 Found
https://example.com/xyz/pqr//////////////////
302 Found
https://example.com/xyz/pqr///////////////////
302 Found

我该如何解决这个问题?我不知道我哪里出错了..!!任何帮助将不胜感激。提前致谢。

这是我的 htaccess 代码:

RewriteEngine on
RewriteCond %{QUERY_STRING} p=3842
RewriteRule ^ /? [R=301,L]

这就是我的 htaccess 代码中的全部内容,其余的只是 301 重定向,仅此而已..!!

【问题讨论】:

  • 发布 .htaccess 文件中处理重定向的代码。
  • 好吧,我已经编辑了我的问题并在那里添加了 htaccess 代码。请检查一下。

标签: .htaccess url url-redirection


【解决方案1】:

要使用.htaccess 删除尾部斜杠,您可以使用:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [R=301,L]

【讨论】:

  • 如果我只是想检查它是否正确重定向,我是否需要对上述代码进行任何更改??? 301 表示在此之前永久重定向,所以我需要首先检查它是否工作的天气。!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-06-19
  • 2017-05-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-22
  • 1970-01-01
相关资源
最近更新 更多