如何根据查询字符串在 apache mod_rewrite 中禁止 url?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1087436/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I make a url forbidden in apache mod_rewrite, based on the query string?
提问by jorgen
How do I make the following url forbidden in apache;
如何在apache中禁止以下网址;
main/index.php?site=ing
main/index.php?site=ing
I have tried the following;
我尝试了以下方法;
RewriteRule ^main/index.php?site=ing - [F]
RewriteRule ^main/index.php?site=ing - [F]
but with no luck...
但没有运气...
回答by Vinko Vrsalovic
You cannot match a query string in the RewriteRule, you have to do
您无法匹配 RewriteRule 中的查询字符串,您必须这样做
RewriteCond %{QUERY_STRING} site=ing #Adjust the regexps with anchors
RewriteRule ^main/index.php - [F]
回答by Gumbo
This should do it:
这应该这样做:
RewriteCond %{QUERY_STRING} (^|&)site=ing(&|$)
RewriteRule ^main/index\.php$ - [F]
回答by MitMaro
Another non apache solution, would be to do this in the index.php file.
另一个非 apache 解决方案是在 index.php 文件中执行此操作。
Add something like this to the top of the page.
将这样的内容添加到页面顶部。
if(isset($_GET['site']) && $_GET['site'] == 'ing'){
header('HTTP/1.1 403 Forbidden');
exit();
}

