我试图拒绝所有,只允许一个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>
有没有办法让这项工作?
10 回答
我知道这个问题已经有了接受的答案,但Apache documentation说:
因此,更具前瞻性的答案是:
希望,我帮助阻止此页面成为那些“过时的教程”之一 . :)
这可以通过使用为该任务设计的指令来改进 .
其中111.222.333.444是您的静态IP地址 .
使用“Order Allow,Deny”指令时,请求必须与Allow或Deny匹配,如果两者都不满足,则请求被拒绝 .
http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html#order
上面的略微修改版本,包括一个自定义页面,显示给那些被拒绝访问的人:
......那些不是来自111.222.333.444的请求会看到specific_page.html
(发布此评论看起来很糟糕,因为新线路丢失)
通过改进以前的答案,可以在对站点进行更改时向用户显示维护页面:
哪里:
#.#.#.#
是您的IP:What Is My IP Address?For
maintenance.html
这里有一个很好的例子:Simple Maintenance Page您可以在htaccess中使用以下内容来允许和拒绝访问您的站点:
如果客户端IP地址与模式匹配,我们首先设置一个env变量 allowedip ,如果模式匹配,则env变量 allowedip 被赋值为 1 .
在下一步中,我们使用Allow,deny指令来允许和拒绝对站点的访问 .
Order deny,allow
表示deny
和allow
的顺序 .deny from all
这一行告诉服务器拒绝所有人 . 最后一行allow from env=allowedip
允许访问我们为其设置env变量的单个IP地址 .用您允许的IP地址替换
1\.2\.3\.4\.5
.参考:
https://httpd.apache.org/docs/2.4/mod/mod_setenvif.html
https://httpd.apache.org/docs/2.4/mod/mod_access_compat.html
我无法使用403方法,因为我想在我的服务器上的子文件夹中维护页面和页面图像,因此使用以下方法重定向到每个人的“维护页面”,但只有一个IP *
资料来源:Creating a holding page to hide your WordPress blog
您可以拥有多个IP甚至其他类型的允许,例如用户,主机名,...更多信息,请点击此处https://www.askapache.com/htaccess/setenvif/
除了@David Brown的回答之外,如果你想阻止IP,你必须首先允许所有IP然后阻止IP:
您可以使用上述任何符号来满足您的CIDR需求 .
如果要使用mod_rewrite进行访问控制,可以使用用户代理,http引用,远程地址等条件 .
例
Refrences: