Html .htaccess 阻止所有但我的 ip
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13934768/
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
.htaccess block all but my ip
提问by ttmt
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 中查看 - 这是执行此操作的正确方法吗?
回答by MickeyRoush
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. So if that's the case you can discard it here.
请注意,如果您已经将规则置于此之上,则“RewriteEngine On”将是多余的。因此,如果是这种情况,您可以在此处丢弃它。
回答by Fenton
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 地址。