【问题标题】:Blocking bad requests with .htaccess file使用 .htaccess 文件阻止错误请求
【发布时间】:2012-01-04 09:35:47
【问题描述】:

我有一个网站被用户点击此 URL 的变体 /index.php?s=

我正在尝试阻止对以下字符串的所有请求,这应该摆脱所有垃圾邮件发送者 php?s=

我似乎遇到的问题是? htaccess 文件中的和 = 是受保护的字符,我只是无法使语法正确。如何在以下场景中使用 php?s=

我试过了

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{REQUEST_URI} ^.(*php?s=).* [NC]
 RewriteRule ^(.*)$ - [F,L]
</IfModule>

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{REQUEST_URI} ^.*php?s=$1&%{QUERY_STRING}.* [NC]
 RewriteRule ^(.*)$ - [F,L]
</IfModule>

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{THE_REQUEST} ^.*(php?s=$1&%{QUERY_STRING}).* [NC]
 RewriteRule ^(.*)$ - [F,L]
</IfModule>

但是没有任何效果。请帮忙!

【问题讨论】:

    标签: apache .htaccess spam-prevention


    【解决方案1】:

    试试

    #all .php requests with s= in querystring
    RewriteCond %{REQUEST_URI} ^.+\.php$ [NC]
    RewriteCond %{QUERY_STRING} ^s=.*$   [NC]
    RewriteRule . - [F,L]
    

    如果您想在任何查询字符串位置阻止s=,请将上面的第二个 rewritecond 替换为

    #block s= in any location
    RewriteCond %{QUERY_STRING} ^(.*&)?s=.*$ [NC]
    

    【讨论】:

      【解决方案2】:

      您也可以在它们执行任何操作之前尝试阻止它们

      .htaccess example

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-12-31
        • 2015-06-08
        • 1970-01-01
        • 1970-01-01
        • 2022-01-11
        • 2015-05-05
        • 1970-01-01
        相关资源
        最近更新 更多