php 路由 隐藏index,CI中路由与伪静态、隐藏index.php(十四)
1,設置路由
默認控制器設置文件
application/config/routes.php$route['default_controller']?=?'welcome';
我們新建一個控制器文件
application/controllers/article.php<?php
class?Article?extends?CI_Controller{
public?function?index(){
echo?"這是一個Article的index方法";
}
}
訪問:index.php/article/index
在寫一個方法public?function?show($id){
echo?'這是文章'.$id;
}
訪問:index.php/article/show/4
或者index.php/article/show/4.html
我們現在路由配置文件里面寫一個正則
application/config/routes.php//index.php/news/201654/4.html
$route['news/[\d]{6}/([\d]+)\.html']='article/show/$1';
2,去掉index.php
前提是需要確定Apache開啟rewrite模塊
wamp/bin/apache/apache2.4.9/conf/httpd.conf
打開注釋LoadModule?rewrite_module?modules/mod_rewrite.so
讓后修改項目配置文件.htaccess文件,添加代碼
RewriteEngine?on
RewriteCond?%{REQUEST_FILENAME}?!-d
RewriteCond?%{REQUEST_FILENAME}?!-f
RewriteRule?^(.*)$?index.php/$1?[QSA,PT,L]
這樣就可以去掉index.php
如果訪問錯誤,再去application/config/config.php文件里$config['index_page']?=?'index.php';//把index.php去掉
總結
以上是生活随笔為你收集整理的php 路由 隐藏index,CI中路由与伪静态、隐藏index.php(十四)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微信公众号教程(16)公司通讯录开发 终
- 下一篇: 动态规划算法php,php算法学习之动态