htaccess阻止对特定URL的GET请求

时间:2015-10-30 04:39:57

标签: apache .htaccess mod-rewrite

Reuqest:

    "GET /api/get_recent_posts/?dev=1&page=1 HTTP/1.1" 200 40831 "-" "Mozilla/5.0 (Linux; U; Android 0.5; en-us) AppleWebKit/522+ (KHTML, like Gecko) Safari/419.3"

尝试使用以下但无效的

来阻止请求
    RewriteEngine On
    RewriteCond %{REQUEST_METHOD} GET
    RewriteRule ^api/get_recent_posts/(.*)$ - [F,NC]

    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^/api/get_recent_posts/(.*)$
    RewriteRule ^(.*)$ - [F,L]

1 个答案:

答案 0 :(得分:1)

试试这个

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\ /api/get_recent_posts/\?dev=([^\s&]+)&page=([^\s&]+)
RewriteRule ^ - [F]