1

我目前正在尝试将两者结合起来 - 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>
4

1 回答 1

0

Make sure AuthUserFile has full path to a valid encrypted passwords file.

Rest of the code, have it like this:

<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>
于 2013-10-15T17:59:07.807 回答