【发布时间】:2016-07-26 12:53:37
【问题描述】:
我有一个网站,我试图设置一个 .htaccess / .htpasswd 密码限制,但同时允许任何具有特定 IP 地址的用户访问。
到目前为止,我在我的 .htaccess 文件中实现了这个,但由于某种原因,如果我访问该站点,无论它允许从哪个 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]
【问题讨论】:
-
你在htaccess中还有其他指令吗?
-
@starkeen 是的,但它只与 php 配置有关,所以我没有将它包含在上面,这就是它:
RemoveType .php AddHandler application/php5-fcgi php Action application/php5-fcgi /cgi-bin/php5fcgi.fcgi
标签: apache .htaccess authentication .htpasswd