限制基于IP地址/块目录 [英] Restrict / Block Directory Based on IP Address

查看:181
本文介绍了限制基于IP地址/块目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图阻止任何人,除1个IP地址目录的访问。这的.htaccess code阻止访问,但禁止访问一切,包括图片,CSS等我需要做什么改变?

Trying to block directory access from everyone except 1 IP address. This .htaccess code blocks access but it blocks access to everything including images, css, etc. What do I need to change?

的RewriteCond%{REMOTE_ADDR}!^ XX \ .XXX \ .XX \ .XXX $
重写规则^ hidedirectory(。*)$ http://site.com/ [R,L]

RewriteCond %{REMOTE_ADDR} !^XX\.XXX\.XX\.XXX$
RewriteRule ^hidedirectory(.*)$ http://site.com/ [R,L]

凡访问mysite.com/hidedirectory除了我应该重定向到mysite.com。有没有更好的,更安全的方式来做到这一点,包括像HTTP响应code?

Anyone accessing mysite.com/hidedirectory except me should redirect to mysite.com. Is there a better, more secure way to do this including something like an http response code?

推荐答案

更​​好的方法是做到这一点在你的 .conf文件文件:

Better way is to do this in your .conf file:

<Directory /hidedirectory>
 options -Indexes
 Order Deny,Allow
 Deny from all
 Allow from XX.XXX.XX.XXX
</Directory> 

这将拒绝everythig喜欢你的重写规则。 但既然要允许访问图像/ CSS等...

This will deny everythig like your rewrite rules. But since you want to allow access to images/css etc...

RewriteCond %{REMOTE_ADDR} !^XX\.XXX\.XX\.XXX$
RewriteCond %{REQUEST_URI} !\.(?:jpe?g|png|gif|css)$ [NC]
RewriteRule ^hidedirectory(.*)$ http://site.com/ [R,L]

添加任何其他扩展到(?:JPE G |?PNG | GIF | CSS)由后缀 | (或)。

Add any other extensions into (?:jpe?g|png|gif|css) suffixed by a |(or).

这篇关于限制基于IP地址/块目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆