[英]Getting .htaccess to allow access for specified IP, but request .htpasswd user + password if from any other IP
我有一个网站,我试图设置.htaccess / .htpasswd密码限制,但同时允许任何具有特定IP地址访问权限的用户。
到目前为止,我已经在我的.htaccess文件中实现了这个,但由于某种原因这个dosnt工作,如果我访问该网站,无论它允许访问哪个IP地址,如果我注释掉行order deny,allow
上面的Allow from 192.87.22.18
,密码保护工作,但是会从每个人请求IP,即使访问192.87.22.18
IP(注意 - 不是我的真实IP)
(由于显而易见的原因,我没有发布我的.htpasswd文件,但它包含1个哈希密码的1行)
有任何想法吗 ?
<Files ~ "^\.(htaccess|.htpasswd)$">
deny from all
</Files>
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.example\.example\.co\.uk)(:80)? [NC]
RewriteRule ^(.*) http://example.example.co.uk/$1 [R=301,L]
order deny,allow
<Files ~ "^\.(htaccess|.htpasswd)$">
deny from all
</Files>
AuthType Basic
AuthName "Please enter your ID and password"
AuthUserFile /var/www/vhosts/example.co.uk/subdomains/example/httpdocs/.htpasswd
AuthGroupFile /dev/null
require valid-user
order deny,allow
Allow from 192.87.22.18
# satisfy any
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule .? %{ENV:BASE}index.php [L]
通过试验和错误我最终使用下面的apache 2.0,取自这里: https : //perishablepress.com/htaccess-password-protection-tricks/
在上面的文章中,他们将代码块包装在<IfModule mod_auth.c>
,这导致代码无法运行(因为我猜这个服务器上的if块等于false)所以我删除了它们。
# password protect excluding specific ip
AuthName "Username and password required"
AuthUserFile /home/path/.htpasswd
AuthType Basic
Require valid-user
Order Deny,Allow
Deny from all
Allow from 111.222.333.444
Satisfy Any
4你应该使用:
AuthType Basic
AuthUserFile c:/wamp/www/_test/www/.htpasswd
AuthName "Protected Area"
<RequireAny>
Require ip 127.0.0.1
Require valid-user
</RequireAny>
order
, deny
, allow
现在已弃用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.