刪除的index.php CI中我使用笨目前正在開發一個網站,我最近在一個路由&的.htaccess問題絆倒了。使用.htaccess文件
基本上,我簡單的網站結構(我們稱之爲我爲簡單起見項目「CIExample」)是如下:
- 首頁
- 關於我們
- 我們的服務
- 新聞
- 聯繫我們
我使用頁面控制器實現。該控制器具有5個功能,要求各網頁的觀點,即:
首頁(),它調用視圖「家」
關於(),它調用視圖「關於我們」等..
此前,訪問「家」,我需要http://localhost/CIExample/index.php/page/home
鍵入的URL窗口,但設置了以下路線後,我才得以刪除「頁」(類名)部分:
$route['default_controller'] = 'page/home';
$route['home'] = 'page/home';
$route['about'] = 'page/about';
$route['service'] = 'page/service';
$route['news'] = 'page/news';
$route['contact'] = 'page/contact';
然而,當我試圖刪除'index.php'時,會出現一些棘手的部分。 我希望能夠通過鍵入http://localhost/CIExample/home
訪問主頁。
所以,我做了很多CI論壇/教程/堆棧溢出的搜索,並發現.htaccess文件的一些代碼:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
或http://ellislab.com/forums/viewthread/197675/#929904
我想這兩個代碼,但沒有工作..
http://localhost/CIExample/home
將指導我未找到404頁,但http://localhost/CIExample/index.php/home
會工作得很好。
我不知道哪裏出了冤屈?是我的routes.php或.htaccess或兩者? 謝謝。
注:我也改變了我的 '配置/ config.php文件' 文件 - >$config['index_page'] = '';
編輯: 最後,它的工作原理! 調整在config文件夾config.php文件和設置後,以下$config['uri_protocol'] = 'PATH_INFO';
(從「AUTO」)。
可選值:
| 'AUTO' Default - auto detects
| 'PATH_INFO' Uses the PATH_INFO
| 'QUERY_STRING' Uses the QUERY_STRING
| 'REQUEST_URI' Uses the REQUEST_URI
| 'ORIG_PATH_INFO' Uses the ORIG_PATH_INFO
說不上有什麼不同,但根據http://www.jotorres.com/2011/12/removing-index-php-from-url-in-codeigniter/一個評論,同樣的代碼可能/可能不會在生產服務器工作。
任何人都可以或許說明理由?
來自CI論壇的代碼應該可以工作。這就是我使用的。您可能需要定義基礎,因爲您位於子目錄中 - RewriteBase/CIExample/ – 2013-03-18 16:46:49
請標記幫助您的答案。它有助於作者和觀衆。 – 2015-10-19 15:41:19