简体   繁体   English

.htaccess阻止我的所有IP

[英].htaccess block all but my ip

I'm trying to do a quick htaccess to block all but my ip. 我正在尝试快速htaccess来阻止除了我的ip之外的所有内容。

I have this 我有这个

    order deny, allow
    deny from all
    allow from "MY IP"

"MY IP" is my ip “我的IP”是我的IP

I can't see if from my ip - is this the correct way to do this ? 我无法看到是否来自我的ip - 这是正确的方法吗?

The most efficient way is to white list yourself using the directive designed for that task. 最有效的方法是使用为该任务设计的指令对自己进行白名单。

Order Allow,Deny
Allow from 123.456.789.123

Where 123.456.789.123 is your static IP address. 其中123.456.789.123是您的静态IP地址。

When using the "Order Allow,Deny" directive the requests must match either Allow or Deny, if neither is met, the request is denied. 使用“Order Allow,Deny”指令时,请求必须与Allow或Deny匹配,如果两者都不满足,则请求被拒绝。

http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html#order http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html#order

Or you could do it with mod_rewrite like so. 或者你可以像这样使用mod_rewrite。

RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.123$
RewriteRule .* - [F]

Note that 'RewriteEngine On' will be redundant if you already have placed in your rules above this one. 请注意,如果您已将规则置于此规则之上,则“RewriteEngine On”将是多余的。 So if that's the case you can discard it here. 所以,如果是这种情况,你可以在这里丢弃它。

You have the correct syntax: 你有正确的语法:

order deny,allow
deny from all
allow from 127.0.0.1

(Note: no quotes around the IP address) (注意:IP地址周围没有引号)

You may want to double check you are using the correct IP Address if you are being denied when you think you should have access. 如果您认为自己应该有权访问,则可能需要仔细检查是否使用了正确的IP地址。

For example, check on http://www.whatsmyip.org/ - maybe you have something in between you and the server, like a proxy, which is being picked up, rather than your own IP Address. 例如,查看http://www.whatsmyip.org/ - 也许你和服务器之间有某些东西,比如代理,而不是你自己的IP地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM