【问题标题】:301 Redirect URLs with capital letters and more than one forward slash301 大写字母和多个正斜杠的重定向 URL
【发布时间】:2018-06-01 06:02:18
【问题描述】:

我需要将在域根之后出现的带有大写字母和任意数量的正斜杠的 URL 永久重定向回根。 例子:

http://www.example.com/abc/pqr/23423532

(这有 2 个正斜杠)

http://www.example.com/AngryBirds

(有 2 个大写字母)

应该重定向到http://www.example.com/

https://www.regextester.com/中尝试了以下操作

^(.*[\/?)$
^([\w]+)(\/+)$
^([A-Z]+)(\/?)

如何编写正则表达式来满足这些要求?

【问题讨论】:

  • 您可以显示您已经尝试/尝试过的当前规则。
  • 在问题中添加了它们。

标签: .htaccess redirect mod-rewrite url-redirection


【解决方案1】:

试试下面,

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/([A-Z]+) [OR]
RewriteCond %{REQUEST_URI} ^/([/]{2,})
RewriteRule ^ http://www.example.com/ [R=301]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-19
    • 2018-12-07
    • 1970-01-01
    • 2019-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多