.htaccess 如何使用htaccess保护codeigniter安装的子目录?
我在根目录中安装了codeigniter,并希望使用htaccess对名为“test”的子目录进行密码保护。不管我怎么做,我总是得到一个“404页未找到”。目录结构为:.htaccess 如何使用htaccess保护codeigniter安装的子目录?,.htaccess,codeigniter,basic-authentication,subdirectory,.htaccess,Codeigniter,Basic Authentication,Subdirectory,我在根目录中安装了codeigniter,并希望使用htaccess对名为“test”的子目录进行密码保护。不管我怎么做,我总是得到一个“404页未找到”。目录结构为: /public_html /css /images /system (codeigniter directory) /test .htaccess .htaccess .htpasswd index.php root.htaccess文件如下所示: RewriteEngi
/public_html
/css
/images
/system (codeigniter directory)
/test
.htaccess
.htaccess
.htpasswd
index.php
root.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>
AuthUserFile/home/dir/.htpasswd
AuthName“保护区”
AuthType Basic
需要用户管理员用户
当我导航到url“”时,我甚至没有得到身份验证提示,只有codeigniter 404页面
请告知
RewriteCond $1 !^(index\.php|addFoldersHere)
请尝试在main.htaccess中使用此规则代替当前的RewriteCond规则。这将允许不忽略您指定的文件夹(其中显示
addFoldersHere
)。确保不要在文件夹列表后添加尾随的|
。以下是我最终解决问题的方法(在CodeIgniter论坛中找到解决方案,网址为:
我的根htaccess中有以下行:
RewriteCond $1 !^(401.shtml)
因此,我的根htaccess中的最后一个块最终如下所示:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(401.shtml)
RewriteRule ^(.*)$ index.php?/$1 [L]
因此,一个解决方案出现了