mod_rewrite和htaccess密码保护在一起

时间:2013-10-15 17:47:08

标签: .htaccess mod-rewrite .htpasswd

我目前正在尝试将两个 - 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>

1 个答案:

答案 0 :(得分:0)

确保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>
相关问题