【问题标题】:Htaccess deny specific get parameterHtaccess 拒绝特定的获取参数
【发布时间】:2015-11-01 09:59:53
【问题描述】:

我想拒绝访问特定的 IP。我试过这个 htaccess 代码但没有用:

<Files "index.php?action=deny">
Order Allow,Deny
Deny from XXXX
Allow from all
</Files>

其中 XXXX 是 IP 地址。我该如何做这样的事情,所以它只会拒绝特定的 get 参数而不是整个文件?

【问题讨论】:

    标签: apache .htaccess get


    【解决方案1】:

    在 2.4 中,用于检查查询字符串

    <If "%{QUERY_STRING} =~ /action=deny/">
      Require all denied
    </If>
    

    在 2.2 中,使用 mod_rewrite:

    RewriteEngine ON
    RewriteCond %{QUERY_STRING} action=deny
    RewriteRule index.php - [F]
    

    【讨论】:

      【解决方案2】:

      Files 指令中的模式具有误导性。如果您想将 URL 与 action=deny 查询参数匹配;你需要使用&lt;Location&gt;:

      <Location /index.php?action=deny>
      

      【讨论】:

      • 位置与查询字符串不匹配
      【解决方案3】:

      您可以在根 .htaccess 中使用此规则:

      RewriteEngine On
      
      RewriteCond %{QUERY_STRING} ^action=deny$ [NC]
      #RewriteCond %{REMOTE_ADDR} =11.22.33.44
      RewriteRule ^index\.php$ - [F]
      

      11.22.33.44替换为您的实际IP地址

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-04-18
        • 2012-04-14
        • 2013-10-07
        • 2011-01-12
        • 2016-07-29
        • 2013-08-27
        • 1970-01-01
        相关资源
        最近更新 更多