.htaccess 阻止除我的 ip 之外的所有内容 [英] .htaccess block all but my ip

查看:29
本文介绍了.htaccess 阻止除我的 ip 之外的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试快速访问 htaccess 以阻止除我的 ip 之外的所有内容.

I'm trying to do a quick htaccess to block all but my ip.

我有这个

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

我的IP"是我的IP

我无法从我的 ip 中看到 - 这是正确的方法吗?

I can't see if from my ip - is this the correct way to do this ?

推荐答案

最有效的方法是使用为该任务设计的指令将自己列入白名单.

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

其中 123.456.789.123 是您的静态 IP 地址.

Where 123.456.789.123 is your static IP address.

当使用Order Allow,Deny"指令时,请求必须匹配 Allow 或 Deny,如果两者都不满足,则请求被拒绝.

When using the "Order Allow,Deny" directive the requests must match either Allow or Deny, if neither is met, the request is denied.

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

或者你可以像这样使用 mod_rewrite 来实现.

Or you could do it with mod_rewrite like so.

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

请注意,如果您已经将规则置于此之上,则RewriteEngine On"将是多余的.因此,如果是这种情况,您可以在此处丢弃它.

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.

这篇关于.htaccess 阻止除我的 ip 之外的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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