apache 需要拒绝除我之外的所有 IP 访问站点并显示友好错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1898536/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 18:29:32  来源:igfitidea点击:

Need to deny all IPs except mine from accessing site and display friendly error

apache.htaccessredirectip-address

提问by alex

I need to deny all IPs except mine.

我需要拒绝除我之外的所有 IP。

I got my outward facing IP from whatismyip.com. Let's assume it is 200.200.200.200

我从 whatismyip.com 获得了我的外向 IP。我们假设它是 200.200.200.200

Here is the beginning of my .htaccess

这是我的 .htaccess 的开头

ErrorDocument 403 /down.html

<Limit GET POST>
order deny,allow
deny from all
allow from 200.200.200.200
</Limit>

This works with the denying part - it shows my down.html page. However it denies me even when I place my correct IP in the .htaccess. Am I doing something wrong?

这适用于拒绝部分 - 它显示了我的 down.html 页面。但是,即使我将正确的 IP 放在 .htaccess 中,它也会拒绝我。难道我做错了什么?

Also the down.html page contains an image - but seeing as all requests are being denied, I had to host it on a different domain to get it to display. My .htaccess skills are a little rusty, but how would I go about allowing that one image request through using .htaccess on this domain?

down.html 页面也包含一个图像 - 但看到所有请求都被拒绝,我不得不将它托管在不同的域上才能显示它。我的 .htaccess 技能有点生疏,但是我将如何通过在此域上使用 .htaccess 来允许该图像请求?

回答by miku

<Limit GET POST>
order allow,deny
allow from 200.200.200.200
deny from all
</Limit>