URI路由帮助CodeIgniter

时间:2011-02-24 13:27:53

标签: php codeigniter routing uri routes

我是codeigniter的新手,实际上是第一次使用它。我正在编辑使用CodeIgniter开发的脚本。它是GroupScript--着名的Groupon的克隆。在此脚本中,可以选择不同的城市。默认情况下,指向不同城市的链接如下:

domain.com/frontend/profile/selectCity/[city_id]

我想要一些uri路由示例,以便我可以将domain.com/[city_id重定向到

domain.com/frontend/profile/selectCity/[city_id]

我研究了一些也有帮助的例子。我能得到的最好的是

domain.com/index.php/[city_id]

被重定向到

domain.com/frontend/profile/selectCity/[city_id]

使用的代码是:$route[’(:num)’] = “frontend/profile/selectCity/$1”;

我无法消除网址中的index.php。任何帮助,将不胜感激。如果我可以从网址中删除index.php内容,那么我就完成了。

Demo groupscript在这里了解我的期望:demo.groupscript.net

4 个答案:

答案 0 :(得分:0)

我没有使用路由功能,但删除index.php可以使用.htaccess文件(如果你使用的是apache)。请参阅this part of the user guide

中标题为删除index.php文件的部分

答案 1 :(得分:0)

通常你会想要这样的东西:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

RewriteCond $1 !^(index\.php|images|robots\.txt|javascript|css)
RewriteRule ^(.*)$ /index.php/$1 [L]

这将重定向.htaccess文件中的所有请求。

答案 2 :(得分:0)

不要忘记在config.php中将默认索引设置为'':

“如果您使用mod_rewrite删除页面设置此变量以使其为空白。”

答案 3 :(得分:0)

删除 " index.php" ,使其在config.php文件中显示为空白。默认文件名将从URL中删除

$config['index_page'] = '';