【问题标题】:Block URLs in .htaccess using regular expression使用正则表达式阻止 .htaccess 中的 URL
【发布时间】:2013-07-02 21:10:54
【问题描述】:

如果几个 URL 与 htaccess 文件中的正则表达式匹配,我想阻止它们。

这些是我想在 htaccess 中阻止的 URL。

在 URL 模式中包含以下内容的任何内容:

  • mp4:
  • wp 内容
  • phpMyAdmin

不区分大小写,请注意“mp4:”必须包含冒号才能匹配表达式。

我怎样才能做到这一点?

谢谢!

【问题讨论】:

标签: php regex apache .htaccess apache2


【解决方案1】:

这应该可行:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^.*(wp-content)|(phpMyAdmin)|(mp4:).* [NC]
RewriteRule ^(.*)$ - [F,L]

然后,对于包含此类字符串的 url,将显示一条禁止消息。例如:

您无权访问此服务器上的 /foomp4:bar/。

【讨论】:

    【解决方案2】:

    我希望这是您正在寻找的示例

    RedirectMatch users/(.+) http://www.exapmles.com/profiles/$1 [R=301,L]

    更多信息可以在这里找到 https://superuser.com/questions/155139/htaccess-301-redirect-with-regular-expressions

    在您的情况下,您应该添加多行! :)

    【讨论】:

      猜你喜欢
      • 2020-11-09
      • 2017-01-08
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多