2010-04-03 56 views
0

我有codeigniter安装在根目录,并希望有一个名为“测试”密码使用htaccess保护的子目录。无论我尝试什么,我都会收到“找不到404页面”。目录结构:如何使用htaccess保护codeigniter安装的子目录?

/public_html 
    /css 
    /images 
    /system (codeigniter directory) 
    /test 
     .htaccess 
.htaccess 
.htpasswd 
index.php 

根.htaccess文件看起来像:

RewriteEngine On 
RewriteBase/

Options -Indexes  

# Removes trailing slashes 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)/$ $1 [L,R=301] 

# Enforce www 
RewriteCond %{HTTP_HOST} !^(www) [NC] 
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301] 


#Checks to see if the user is attempting to access a valid file, 
#such as an image or css document, if this isn't true it sends the 
#request to index.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !^(.*)test(.*)  
RewriteRule ^(.*)$ index.php?/$1 [L] 

的/test/.htaccess文件:

AuthUserFile /home/dir/.htpasswd 
AuthName "Protected Area" 
AuthType Basic 
<limit GET POST PUT> 
    require user adminuser 
</limit> 

我还没有得到验证提示,当我导航到URL“http://www.mydomain.com/test/”时,只是codeigniter 404页面。

请指教!

回答

2

下面是我终于解开了它(http://codeigniter.com/forums/viewthread/56677/P15/在笨论坛找到解决方案):

我此行我的根htaccess的:

RewriteCond $1 !^(401.shtml) 

所以在我的根htaccess的最终块结束看起来像这样:

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond $1 !^(401.shtml) 
RewriteRule ^(.*)$ index.php?/$1 [L] 

因此松了一口气解决方案。

0
RewriteCond $1 !^(index\.php|addFoldersHere) 

试试这个来代替你现在的主要.htaccess中的RewriteCond规则。这将允许你指定的文件夹(它说addFoldersHere)不被忽略。确保您不要在文件夹列表后添加尾随|

+0

这对我来说不起作用,谢谢你的建议。 – 2010-04-07 13:19:24