您当前的位置: 首页 > 学无止境 > 网站建设 网站首页网站建设
CI中的路由与伪静态、隐藏index.php入口文件
发布时间:2020-01-23 20:19:54编辑:雪饮阅读()
路由
有路由如:http://localhost/index.php/news/202001/2.html
在application/config/routes.php中配置如:
$route["news/[\d]{6}/([\d]+)\.html"]="user/show/$1";
则相当于该路由被访问时自动跳转到了http://localhost/index.php/user/show/2
则有user控制器的show方法如:
public function show($id){
echo $id;
}
隐藏index.php
上面的路由中有包含index.php,当我们实现了隐藏index.php后路由可以简化如:
http://localhost/news/202001/2.html
在项目根目录即站点根目录建立文件.htaccess如:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
若用的是apache环境则你可能还需要注意如下配置
DocumentRoot "C:\phpStudy\PHPTutorial\WWW"
<Directory />
Options +FollowSymLinks +SymLinksIfOwnerMatch
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
关键字词:ci,路由,伪静态,隐藏index.php
上一篇:CI中的url相关函数
下一篇:CI中的分页