CI中的路由规则

来源:互联网 发布:h3c路由器封端口 编辑:程序博客网 时间:2024/05/21 17:20

第一步:


创建一个隐藏文件(.htaccess);

将CI手册中的规则写进文件中

RewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^(.*)$ index.php/$1 [L]

移除 URL 中的 index.php

默认情况,你的 URL 中会包含 index.php 文件:

example.com/index.php/news/article/my_article

下一步:

在config/config.php/中修改URL后缀(即绿色所代表的内容)

添加 URL 后缀($config['url_suffix'] = '.html';

在你的 config/config.php 文件中你可以指定一个后缀,CodeIgniter 生成 URL 时会自动添加上它。例如,一个像这样的 URL:

example.com/index.php/products/view/shoes

你可以添加一个后缀,如:.html ,这样页面看起来就是这个样子:

example.com/index.php/products/view/shoes.html

最后是需要你在routes.php中写正则

$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['welcome/lists_(:num)_(:num)'] = 'welcome/lists/$1/$2';

最后就搞定了;

0 0
原创粉丝点击