我對CodeIgniter相當陌生,並且完成了我的第一個項目。但是,在我將其放在我的託管站點上之前,我想使用CodeIgniter在config文件夾中提供的routes.php文件清理URL。簡單的URL路由不能與CodeIgniter一起使用
我的網站會加載使用以下網址:
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
,它也將使用默認的控制器的網址加載網頁: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規則是什麼樣子的? – David 2013-03-21 18:49:27
大衛,我沒有觸及mod_rewrite規則。你的意思是.htaccess文件嗎?它說:拒絕所有在那裏..我認爲這是不好的? – ErinSKabbash 2013-03-21 18:53:13
看着你回答的問題,它似乎不像你有.htaccess下的mod_rewrite規則。否則,我強烈建議你花一些時間閱讀Apache的用戶指南 - http://httpd.apache.org/docs/2.2/它們相當乾燥,但重要的是你對Apache可以爲你做什麼或可能做什麼有所瞭解。 – David 2013-03-21 21:11:17