在CI框架中如何实现伪静态

第一步:在根目录下(index.PHP)同一级目录下建立一个.htaccess这个文件文件内容(即红色标识所显示的内容)

 

URI 类 和 URL 辅助函数 包含了一些函数可以让你更容易的处理 URI 数据,另外,你的 URL 可以通过 URI 路由 进行重定向从而得到更大的灵活性。

移除 URL 中的 index.php

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

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

如果你的 Apache 服务器启用了 mod_rewrite ,你可以简单的通过一个 .htaccess 文件再加上一些简单的规则就可以移除 index.php 了。下面是这个文件的一个例子, 其中使用了 "否定条件" 来排除某些不需要重定向的项目:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

第二步:

 

在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

第三步:

在config/routes.php中修改配置且添加正则匹配

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

 

具体案例:

 

[python] view plain copy
 
  1. public function lists($page,$search){  
  2.         echo $page;  
  3.         echo "</br>";  
  4.         echo $search;  
  5.     }  



 

http://localhost/two_exam/welcome/lists_13126726903_15135374298.html

案例效果如下:

13126726903

15135374298

posted @ 2016-12-22 15:58  帽子戏法  阅读(937)  评论(0编辑  收藏  举报
全部 html css js Linux php MySQL seo web git other 联系 管理