首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >拒绝所有,只允许一个IP通过htaccess

拒绝所有,只允许一个IP通过htaccess
EN

Stack Overflow用户
提问于 2010-12-09 23:50:56
回答 8查看 510.9K关注 0票数 170

我试图否认所有这些,并且只允许一个IP。但是,我希望有以下的htaccess为该单一的IP工作。我找不到一种方法来让这两个选项都起作用:拒绝所有和只允许一个,外加以下选项:

代码语言:javascript
复制
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>

有没有办法做到这一点呢?

EN

回答 8

Stack Overflow用户

回答已采纳

发布于 2010-12-10 00:13:28

代码语言:javascript
复制
order deny,allow
deny from all
allow from <your ip> 
票数 402
EN

Stack Overflow用户

发布于 2012-12-19 02:06:39

这可以通过使用为该任务设计的指令来改进。

代码语言:javascript
复制
ErrorDocument 403 /specific_page.html
Order Allow,Deny
Allow from 111.222.333.444

其中111.222.333.444是您的静态IP地址。

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

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

票数 41
EN

Stack Overflow用户

发布于 2012-05-18 21:35:43

对上面的版本稍作修改,包括向那些被拒绝访问的人显示的自定义页面:

代码语言:javascript
复制
ErrorDocument 403 /specific_page.html
order deny,allow
deny from all
allow from 111.222.333.444

以这种方式...and那些不是来自111.222.333.444的请求将看到specific_page.html

(这条评论看起来很糟糕,因为新的行会丢失)

票数 32
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4400154

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档