我目前正在尝试将两者结合起来 - htaccess 密码保护和mod_rewrite。我的问题是,下面的代码导致错误:"未指定输入文件。
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
DirectoryIndex index.php
AuthType Basic
AuthName "Password Protected Area"
AuthUserFile .htpasswd
Require valid-user
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
谁能看到,我做错了什么?
编辑#1:
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
DirectoryIndex index.php
AuthType Basic
AuthName "Password Protected Area"
AuthUserFile /.htpasswd
Require valid-user
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
</IfModule>
确保AuthUserFile
具有有效加密密码文件的完整路径。
代码,如下所示:
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
DirectoryIndex index.php
AuthType Basic
AuthName "Password Protected Area"
AuthUserFile /full/path/to/.htpasswd
Require valid-user
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^((?!public/).*)$ /public/$1 [L,NC]
</IfModule>