URL路由解析说明:
- InitPHP的框架URL路由分为三种形式,原生、path模式、rewrite模式,HTML模式
- 原生模式:index.php?c=index&a=run
- rewrite模式:/index/run/?id=1 (需要开启服务器rewrite模块,并且配置.htaccess)
- path模式:/index/run/id/1 (需要开启服务器rewrite模块,并且配置.htaccess)
- html模式: user-index-run.htm?uid=100 (需要开启服务器rewrite模块,并且配置.htaccess)
路由配置:
- 配置文件参数:$InitPHP_conf['isuri']
- 三种参数:default、path和rewrite,html
/**
* 路由访问方式
* 1. 如果为true 则开启path访问方式,否则关闭
* 2. default:index.php?m=user&c=index&a=run
* 3. rewrite:/user/index/run/?id=100
* 4. path: /user/index/run/id/100
* 5. html: user-index-run.htm?uid=100
* 6. 开启PATH需要开启APACHE的rewrite模块,详细使用会在文档中体现
*/
$InitPHP_conf['isuri'] = 'rewrite';
Apache Rewrite:
- 开启rewrite模块
- 在添加.htaccess文件,文件中放入下面的rewrite代码,就可以指向到Index.php了
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
Nginx的话所有请求指到index.php入口文件上即可:
location / {
root /var/www/phpshuo.com/;
index index.html index.htm;
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}