如何使用 htaccess 保护 codeigniter 安装的子目录?
我在根目录安装了 codeigniter,并且希望有一个名为“test”的子目录,并使用 htaccess 进行密码保护。无论我如何尝试,我总是收到“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>
当我导航到 url“http://www.mydomain.com/test/"。
请指教!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我最终解决它的方法(在 CodeIgniter 论坛中找到解决方案 http://codeigniter.com /forums/viewthread/56677/P15/):
我把这行代码连接到了我的根 htaccess:
所以我的根 htaccess 中的最后一个块最终看起来像这样:
所以松了一口气,解决方案就在那里。
Here is how I finally solved it (found solution in CodeIgniter forum at http://codeigniter.com/forums/viewthread/56677/P15/):
I had this line to my root htaccess:
So the final block in my root htaccess ended up looking like this:
So relieved a solution was out there.
尝试用此方法代替主 .htaccess 中当前的 RewriteCond 规则。这将允许您指定的文件夹(其中显示
addFoldersHere
)不被忽略。确保您没有在文件夹列表后添加尾随|
。Try this in place of your current RewriteCond rule in your main .htaccess. This will allow folders you specify (where it says
addFoldersHere
) to not be ignored. Make sure you don't add a trailing|
after the list of folder(s).