2013-06-22 158 views
0

我遇到问题,我想使用.htaccess保护我的网站的管理面板,但它的CGI脚本。阻止.htaccess中的特定网址并允许通过IP访问

从web浏览器,它看起来像:当然其/cgi-bin/index.cgi?op=adminpanel的http://mysite.com/?op=adminpanel

我已经试过:

<files index.cgi?op=adminpanel> 
order deny,allow 
deny from all 
allow from my.ip.address 
</files> 

但不工作,当我使用<files index.cgi></files>时工作,但整个网站得到了403错误除了我的ip以外的每个人

现在我与测试:

RewriteEngine on 
RewriteCond %{REMOTE_ADDR} !(my.IP) 
RewriteCond %{QUERY_STRING} !(?op=adminpanel) 
RewriteRule index.cgi - [F] 

任何帮助将不胜感激

回答

2

this article你可以做这样的:

比方说,你想阻止IP地址123.255。 123.255访问www.mydomain.com/index.php?option=com_my_special_component页面。这里是你如何写规则:

RewriteEngine On 
RewriteCond %{REMOTE_ADDR} ^123\.255\.123\.255 
RewriteCond %{QUERY_STRING} option=com_my_special_component [NC] 
RewriteRule ^(.*)$ index.php [F,L] 

第一行只是打开URL重写。第二行匹配IP地址(在每个点之前使用反斜杠),第三行匹配查询字符串(即URL中的?之后的任何内容) - 在这种情况下,如果option = com_my_special_component位于URL中的任何位置之后 ? (例如,index.php?id = 1 & option = com_my_special_component & action = dostuff仍然会与此规则匹配)。该行末尾的[NC]指示它应用规则,而不管URL中的任何字符是大写还是小写。最后一行将用户重定向到带有'禁止'标头的index.php - 这样他们将在浏览器中收到一条错误消息,并告诉mod_rewrite停止解释任何进一步的重写规则。

如果你想禁止多个IP地址,您可以添加新线他们,但你需要一个[OR]标志添加到每行末尾除了最后一个 - 例如:

RewriteEngine On 
RewriteCond %{REMOTE_ADDR} ^123\.255\.123\.255 [OR] 
RewriteCond %{REMOTE_ADDR} ^124\.255\.124\.255 [OR] 
RewriteCond %{REMOTE_ADDR} ^125\.255\.125\.255 
RewriteCond %{QUERY_STRING} option=com_my_special_component [NC] 
RewriteRule ^(.*)$ index.php [F,L] 

由于您可以阻止访问管理页面,因此您可能只想允许您的IP。在这种情况下,你只需在IP地址前面加一个感叹号来表示它是否是除此之外的任何IP,然后重写。

RewriteEngine On 
RewriteCond %{REMOTE_ADDR} !^123\.255\.123\.255 
RewriteCond %{REMOTE_ADDR} !^124\.255\.124\.255 
RewriteCond %{REMOTE_ADDR} !^125\.255\.125\.255 
RewriteCond %{QUERY_STRING} option=com_my_special_component [NC] 
RewriteRule ^(.*)$ index.php [F,L] 

希望有所帮助。

0

.htaccess文件中试试这个:

RewriteEngine On 
RewriteCond %{REQUEST_URI} ^/admin 
RewriteCond %{REMOTE_ADDR} !=10.0.0.1 
RewriteCond %{REMOTE_ADDR} !=10.0.0.2 
RewriteCond %{REMOTE_ADDR} !=10.0.0.3 
RewriteRule ^(.*)$ - [R=403,L] 
if the url begins with /admin and the remote address is not one of the three listed, send the browser on its merry way. 

参考:https://www.concrete5.org/community/forums/chat/restrict-urls-starting-with-abc-to-specific-ips-.htaccess-guru

你可以改变这一行(RewriteCond %{REQUEST_URI} ^/admin)本:

RewriteCond %{REQUEST_URI} .*/admin

非常网址包含“/ admin” 的。

相关问题