删除的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