如何根据查询字符串在apache mod_rewrite中禁止使用url?

时间:2009-07-06 14:55:55

标签: apache mod-rewrite query-string

如何在apache中禁止以下网址;

main/index.php?site=ing

我尝试了以下内容;

RewriteRule ^main/index.php?site=ing - [F]

但没有运气......

3 个答案:

答案 0 :(得分:16)

cannot match a query string in the RewriteRule,你必须做

RewriteCond %{QUERY_STRING} site=ing     #Adjust the regexps with anchors
RewriteRule ^main/index.php - [F]

答案 1 :(得分:3)

这应该这样做:

RewriteCond %{QUERY_STRING} (^|&)site=ing(&|$)
RewriteRule ^main/index\.php$ - [F]

答案 2 :(得分:1)

另一个非apache解决方案是在index.php文件中执行此操作。

在页面顶部添加这样的内容。

if(isset($_GET['site']) && $_GET['site'] == 'ing'){
    header('HTTP/1.1 403 Forbidden');
    exit();
}