Codeigniter路由不能在生产环境中工作


Codeigniter Routing not working on Production Environment

我在本地机器上运行得很好,但当我推送到服务器时,路由崩溃了。对于我的设置,codeigniter从名为"secure"的子目录运行,所以这是我在"secure"目录中创建的。htaccess文件:

RewriteEngine on
RewriteBase /secure/
RewriteRule ^assets/less/icons/(.*)$ /secure/assets/icons/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

路由文件当前是这样的:

$route['logout'] = "secure/logout";
$route['passwordReset'] = "secure/PasswordReset";
$route['default_controller'] = 'secure';

在我的本地设置中,如果您要访问URL '/secure/dashboard',控制器' dashboard .php'将被正确调用并启动索引。但是,如果我在服务器上访问相同的URL,它会尝试调用控制器'Secure.php'而不是'Dashboard.php'。

我不确定我的本地环境和服务器之间有什么不同,那就是停止服务器忽略URL的"安全"部分,我认为。htaccess文件中的这一行应该整理子目录:'RewriteBase/secure/'。

现在非常欢迎任何反馈:/

我终于弄清了问题的真相。我的服务器拥有几个不同的开发环境,这些环境不是直接从http根目录运行的。这导致变量$_SERVER['SCRIPT_NAME']等于'/staging/secure/index.php',而不是'/secure/index.php';所以我只是在index.php文件的顶部添加了以下内容

$_SERVER['SCRIPT_NAME'] = '/secure/index.php';