我在使用自定义(有点奇怪)htaccess文件夹映射时遇到codeignighter的问题。然而,从技术上讲,它应该工作,但它没有。有人能帮帮我吗?
场景1(工作正常):
文件夹结构和密钥文件
/ is the website root
/.htaccess
/api/ <this is the CodeIgniter Root, with index.php and default CI .htaccess>
/. htaccess:
RewriteEngine On
RewriteRule ^api/(.*)$ /api/$1 [L]
访问mydomain.com/api/admin/,例如,我得到我的admin-controller/index操作,并加载视图。
在index.php上显示$_REQUEST的var_dump
array (size=1)
'admin/' => string '' (length=0)
场景2(不工作):
文件夹结构和密钥文件
/.htaccess
/current/.htaccess
/current/api/ <this is the CodeIgniter Root, with index.php and default CI .htaccess, this is the same folder/files/htaccess as above scenario>
/. htaccess:
RewriteEngine On
RewriteRule ^(.*)$ /current/$1 [L]
/经常/. htaccess:
RewriteEngine On
RewriteRule ^api/(.*)$ /api/$1 [L]
例如,访问mydomain.com/api/admin/使我进入Codeigniter 404 Page/view.
在index.php上显示$_REQUEST的var_dump(与场景1相同)
array (size=1)
'admin/' => string '' (length=0)
这是怎么回事?我知道htaccess重写是奇怪的,但就Codeigniter所看到的,路由是相同的(admin/)。但它们的行为不同。为什么?我尝试了我能想到的一切,据我所见,编码器看到了请求对象的正确路径,但CI路由器不知何故不能正确使用它。
感谢任何帮助,让我知道,如果你能想到什么,我可以试着帮助进一步调试。
注意:我使用双重htaccess的原因是,我可以根据时间/场景调度不同的CI实例(你可以使用重写条件来服务不同的文件夹,而不是"当前"文件夹)。我目前没有使用这个,所以在场景2中,根目录只有一个"当前"文件夹。
从CodeIgniter的URI中删除index.php可能是一件痛苦的事情。上周我遇到了一个类似的情况:我有我的根目录在/var/www/html
和/ci
里面我的项目…所以在/ci
中我有如下。htaccess:
RewriteEngine on
RewriteCond $1 !^(index.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
在apache2配置文件中,我添加了以下内容:
<Directory /var/www/html/ci/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
也检查在application/config/config.php
你有:
$config['uri_protocol'] = 'REQUEST_URI';
您将请求重定向到一个文件夹,而实际上您应该将这些重定向到CodeIgniter的index.php文件。
例句:
RewriteRule ^api/(.*)$ /api/index.php?/$1 [L]
这是假设你有'index_page'设置为空字符串在你的配置文件,如果它设置为index.php,那么当请求的东西,你应该包括index.php在url