我试图拒绝所有,只允许一个IP.但是,我想让以下htaccess为该单个IP工作.我找不到兼顾两者的方法:拒绝所有并且只允许一个,加上以下选项:
<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>
Run Code Online (Sandbox Code Playgroud)
有没有办法让这项工作?
小智 342
order deny,allow
deny from all
allow from <your ip>
Run Code Online (Sandbox Code Playgroud)
Rok*_*gar 105
我知道这个问题已经有了一个公认的答案,但是Apache文档说:
mod_access_compat提供的Allow,Deny和Order指令已弃用,将在以后的版本中消失.您应该避免使用它们,并避免过时的教程建议使用它们.
因此,更具前瞻性的答案是:
<RequireAll>
Require ip xx.xx.xx.xx yy.yy.yy.yy
</RequireAll>
Run Code Online (Sandbox Code Playgroud)
希望,我帮助阻止此页面成为那些"过时的教程"之一.:)
小智 38
这可以通过使用为该任务设计的指令来改进.
ErrorDocument 403 /specific_page.html
Order Allow,Deny
Allow from 111.222.333.444
Run Code Online (Sandbox Code Playgroud)
其中111.222.333.444是您的静态IP地址.
使用"Order Allow,Deny"指令时,请求必须与Allow或Deny匹配,如果两者都不满足,则请求被拒绝.
http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html#order
Oli*_*vic 31
上面的略微修改版本,包括一个自定义页面,显示给那些被拒绝访问的人:
ErrorDocument 403 /specific_page.html
order deny,allow
deny from all
allow from 111.222.333.444
Run Code Online (Sandbox Code Playgroud)
......那些不是来自111.222.333.444的请求会看到specific_page.html
(发布此评论看起来很糟糕,因为新线路丢失)
通过改进以前的答案,可以在对站点进行更改时向用户显示维护页面:
ErrorDocument 403 /maintenance.html
Order Allow,Deny
Allow from #.#.#.#
Run Code Online (Sandbox Code Playgroud)
哪里:
#.#.#.#
是你的IP:我的IP地址是什么?maintenance.html
有一个很好的例子在这里:简单的维护页在 .htaccess 文件中添加以下命令。并将该文件放入您的 htdocs 文件夹中。
Order Deny,Allow
Deny from all
Allow from <your ip>
Allow from <another ip>
Run Code Online (Sandbox Code Playgroud)
小智 5
除了@David Brown 的回答之外,如果你想阻止一个 IP,你必须首先允许所有,然后像这样阻止 IP:
<RequireAll>
Require all granted
Require not ip 10.0.0.0/255.0.0.0
Require not ip 172.16.0.0/12
Require not ip 192.168
</RequireAll>
Run Code Online (Sandbox Code Playgroud)
10.0.0.0
到10.255.255.255
172.16.0.0
到172.31.255.255
192.168.0.0
到192.168.255.255
您可以使用上面提到的任何符号来满足您的 CIDR 需求。