[英]CodeIgniter 3 controller methods not working when running in sub-directory
我目前正在为客户端构建一个新的子系统,它将在https://example.com/new-subsystem之类的子目录上运行。
他们现有的网站是本机/硬编码 PHP 所以我必须在根目录上创建一个新文件夹并将 CodeIgniter 3 框架放在那里。 我配置了base_url,瞧。 它工作正常。
现在的问题是,当我尝试在 controller 中创建一个新方法时,它返回错误 404,似乎服务器正试图从字面上处理请求,而不是让 CodeIgniter 处理它。
例子
当我尝试访问https://example.com/new-subsystem时,它工作正常。
但是,当我尝试访问https://example.com/new-subsystem/test时,它会显示错误 404,并且似乎服务器正在尝试查找另一个文件夹。 这里是实际route.php
, config.php
, controller
我相信问题不在于这三个。
路线.php
$route['default_controller'] = 'lockdown';
$route['test'] = 'lockdown/test';
config.php
$config['base_url'] = 'http://localhost/project-lockdown/tutorials/';
Lockdown.php(控制器)
class Lockdown extends CI_Controller {
public function index()
{
// This is working by default. It shows on http://localhost/project-lockdown/tutorials/
echo "Hello World!"
}
public function test(){
// This should show on http://localhost/project-lockdown/tutorials/test
echo "Hello, this is a test method and it is not working. Error 404 is shown!";
}
}
主要问题:如何告诉服务器我希望 CodeIgniter 处理http://localhost .
现在,我被困在这里,仍然试图通过互联网找到解决方案,并且可以找到东西。 我不是.htaccess
人,所以我认为这与.htaccess
魔法或其他东西(我现在正在尝试学习)有关。
任何帮助,将不胜感激。 如果我只是在根文件夹中放入 CodeIgniter,则不会出现此问题。
先感谢您。
您需要 URL 中的 append index.php 才能访问您的控制器/方法。 尝试 -
localhost/project-lockdown/tutorials/index.php/(controller)/
您可以通过重写.htaccess
文件中的一些规则来删除index.php
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.