我想使用htaccess来允许访问索引文件加上一些其他的目录(index.php),但需要一个用户/通过目录中的其他一切。 现在我有:
AuthName "SomeServer" AuthUserFile /path/to/.htpasswd AuthGroupFile /dev/null Require valid-user AuthType Basic <FilesMatch "(index.php)|(login.php)"> Allow from all Satisfy any </FilesMatch>
这允许用户访问index.php和login.php并拒绝目录的其余部分。 但是,只要用户请求URL中没有index.php的目录,如下所示:
http://www.example.com/dir
提示用户login。 但是,如果用户在这里:
http://www.example.com/dir/index.php
然后index.php显示没有login提示。
我需要更改哪些内容以允许用户访问http://www.example.com/dir,然后直接访问http://www.example.com/dir/index.php,而无需提示login需要在目录中的任何其他login?
更新:不知道它的问题,但我切换身份validation使用mod_auth_mysql。 仍然使用我的htaccess文件的同一部分,仍然面临同样的问题。
你可以尝试像下面这样的东西
<VirtualHost *:80> ServerName localhost DocumentRoot /vhosts/default DirectoryIndex index.php <Directory /vhosts/default> Options -Indexes AllowOverride All Order allow,deny Allow from all </Directory> <Location ~ ^/dir/(index|login)\.php$> Allow from all Satisfy any </Location> <Location ~ ^/dir/?$> Allow from all Satisfy any </Location> </VirtualHost>
做一些基本的testing
# curl -I http://localhost/ HTTP/1.1 401 Authorization Required Date: Fri, 19 Feb 2016 10:03:38 GMT Server: Apache/2.2.15 (CentOS) WWW-Authenticate: Basic realm="SomeServer" Content-Type: text/html; charset=iso-8859-1 # curl -I http://localhost/index.php HTTP/1.1 401 Authorization Required Date: Fri, 19 Feb 2016 10:03:43 GMT Server: Apache/2.2.15 (CentOS) WWW-Authenticate: Basic realm="SomeServer" Content-Type: text/html; charset=iso-8859-1 # curl -I http://localhost/dir/index.php HTTP/1.1 200 OK Date: Fri, 19 Feb 2016 10:03:49 GMT Server: Apache/2.2.15 (CentOS) X-Powered-By: PHP/5.6.16 Content-Type: text/html; charset=UTF-8 # curl -I http://localhost/dir/ HTTP/1.1 200 OK Date: Fri, 19 Feb 2016 10:03:52 GMT Server: Apache/2.2.15 (CentOS) X-Powered-By: PHP/5.6.16 Content-Type: text/html; charset=UTF-8 # curl -I http://localhost/dir/some_file.php HTTP/1.1 401 Authorization Required Date: Fri, 19 Feb 2016 10:04:07 GMT Server: Apache/2.2.15 (CentOS) WWW-Authenticate: Basic realm="SomeServer" Content-Type: text/html; charset=iso-8859-1 # curl -I http://localhost/dir HTTP/1.1 301 Moved Permanently Date: Fri, 19 Feb 2016 10:04:14 GMT Server: Apache/2.2.15 (CentOS) Location: http://localhost/dir/ Content-Type: text/html; charset=iso-8859-1