【发布时间】:2013-03-11 10:23:47
【问题描述】:
我对 CodeIgniter 还很陌生,并且完成了我的第一个项目。但是,在我把它放到我的托管站点之前,我想使用 CodeIgniter 在 config 文件夹中提供的 routes.php 文件来清理 URL。
我的网站将使用以下网址加载:
http://fakehost:8888/TheWorksPlumbing/index.php/theWorksPlumbingController/index/home
http://fakehost:8888/TheWorksPlumbing/index.php/theWorksPlumbingController/index/about
http://fakehost:8888/TheWorksPlumbing/index.php/theWorksPlumbingController/index/services
它还将使用默认控制器 url 加载主页:http://fakehost:8888/TheWorksPlumbing/
但是,我希望网站的每个页面都有一个 url,但无法使其正常工作。例如我想要:
http://fakehost:8888/TheWorksPlumbing/home
http://fakehost:8888/TheWorksPlumbing/about
http://fakehost:8888/TheWorksPlumbing/services
这里是 theWorksPlumbingController 控制器文件的代码:
class TheWorksPlumbingController extends CI_Controller {
public function index($page = 'home'){
if ( !file_exists('application/views/'.$page.'.php') ) {
show_404();
}
$this->load->view('templates/header');
$this->load->view($page);
$this->load->view('templates/footer');
}
}
这是我的 routes.php 文件中不起作用的代码:
$route['default_controller'] = "theWorksPlumbingController";
$route['404_override'] = '';
$route['(:any)'] = "index.php/theWorksPlumbingController/index";
我需要添加或更改什么才能让网站仅加载 /home 或 /about 或 /services?
【问题讨论】:
-
快速健全性检查,您的 mod_rewrite 规则是什么样的?
-
大卫,我还没有触及 mod_rewrite 规则。你的意思是 .htaccess 文件?它说:拒绝那里的一切。我认为这很糟糕?
-
查看您已回答的问题,您似乎没有在 .htaccess 下设置 mod_rewrite 规则。否则,我强烈建议您花一些时间阅读 Apache 的用户指南 - httpd.apache.org/docs/2.2 它们相当枯燥,但重要的是您了解 Apache 正在或可能为您做什么。
标签: php codeigniter routing