我在根目录下安装了codeigniter,并希望使用htaccess保护一个名为“test”密码的子目录。无论我尝试什么,我都会收到“404页面未找到”。目录结构是:
/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>
当我导航到网址“http://www.mydomain.com/test/”时,我甚至没有收到身份验证提示,只有codeigniter 404页面。
请指教!
答案 0 :(得分:2)
以下是我最终解决的问题(在http://codeigniter.com/forums/viewthread/56677/P15/的CodeIgniter论坛中找到解决方案):
我有这条线到我的根htaccess:
RewriteCond $1 !^(401.shtml)
所以我的root htaccess中的最后一个块看起来像这样:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(401.shtml)
RewriteRule ^(.*)$ index.php?/$1 [L]
解除了解决方案。
答案 1 :(得分:0)
RewriteCond $1 !^(index\.php|addFoldersHere)
在主.htaccess中尝试使用此代替当前的RewriteCond规则。这将允许您指定的文件夹(其中显示addFoldersHere
)不被忽略。确保不在文件夹列表后面添加尾随|
。