我正在使用此代码只允许我的IP访问该网站
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^xxx\.xxx\.xxx\.xxx
RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintenance.html [R=302,L]
</IfModule>
现在我想允许我的朋友ip访问该网站。如何在htaccess中指定多个ips?
答案 0 :(得分:10)
使用.htaccess文件限制网站并添加:
#...
Allow from IP/SubnetMask
Allow from IP/SubnetMask
#...
答案 1 :(得分:1)
诀窍是添加一个对允许的IP没有任何作用的规则,而不是为维护添加规则;因为你可以将规则标记为Last,这意味着下一个规则不会被处理(除非规则没有修改地址,这将通过.htaccess再触发一次)。在你的情况下,它看起来像:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REMOTE_ADDR} xxx\.xxx\.xxx\.xxx [OR]
RewriteCond %{REMOTE_ADDR} xxx\.xxx\.xxx\.xxy [OR]
RewriteCond %{REMOTE_ADDR} xxx\.xxx\.xxx\.xxz
RewriteRule .* - [L] #do notthing
#if we are here, the IP is not in the allowed list, redirect
RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintenance.html [R=302,L]
</IfModule>
答案 2 :(得分:0)
尝试添加另一个RewriteCond
并将[OR]
标志添加到其他IP条件:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteCond %{REMOTE_ADDR} !^xxx\.xxx\.xxx\.xxx [OR]
RewriteCond %{REMOTE_ADDR} !^yyy\.yyy\.yyy\.yyy
RewriteRule .* /maintenance.html [R=302,L]
</IfModule>
希望有帮助...
答案 3 :(得分:0)
这是我们自2013年以来一直在使用的内容
[ 31% 5/16] build out/target/product/generic_arm64_ab/obj/ETC/plat_seapp_contexts_intermediates/plat_seapp_contexts
FAILED: out/target/product/generic_arm64_ab/obj/ETC/plat_seapp_contexts_intermediates/plat_seapp_contexts
/bin/bash -c "out/host/linux-x86/bin/checkseapp -p out/target/product/generic_arm64_ab/obj/ETC/sepolicy_intermediates/sepolicy -o
out/target/product/generic_arm64_ab/obj/ETC/plat_seapp_contexts_intermediates/plat_seapp_contexts system/sepolicy/private/seapp_contexts
vendor/dummy/michel/frameworks/Mye/sepolicy/private/seapp_contexts vendor/dummy/michel/frameworks/core/sepolicy/private/seapp_contexts
vendor/dummy/michel/frameworks/Mye/sepolicy/private/seapp_contexts vendor/dummy/services/sepolicy/private/seapp_contexts"
Error: Duplicate line detected in file: vendor/dummy/michel/frameworks/Mye/sepolicy/private/seapp_contexts
Lines 1 and 1 match on everything!
03:04:57 ninja failed with: exit status 1
#### failed to build some targets (7 seconds) ####
第6行的Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^/maintenance(.+)/(.+)/ maintenance.php?id=$1&name=$2 [L]
RewriteCond %{REQUEST_URI} !^/maintenance/index\.html?text=Coming+Back+Soon$
RewriteCond %{REMOTE_ADDR} !^11\.111\.111\.111 [AND]
RewriteCond %{REMOTE_ADDR} !^11\.111\.111\.112
RewriteCond %{REQUEST_URI} !\.(?:css|js|jpe?g|gif|png|woff2|ttf)$ [NC]
RewriteRule ^(.*)$ https://www.cloudianos.com/maintenance/index.html?text=Coming+Back+Soon [R=302,L]
是至关重要的,因为两个IP地址都被取反,因此[AND]
不能同时适用于它们两个。原因如下:[OR]
会重定向您,除非您的设备同时使用两个IP请求资源(这实际上是不可能的),因为if the IP is not 11.111.111.111 OR 11.111.111.112
的两面始终为真。如果IP为if
,则该陈述为真,因为它不是11.111.111.111
,反之亦然。
以下是此代码的条件:
11.111.111.112
,.css
,.js
等文件,请不要重定向用户(以便维护页面可以请求使用此类文件)