8

ThinkPHP的几种路由形式总结

 4 years ago
source link: http://www.cnblogs.com/a609251438/p/12589111.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

本篇文章总结了ThinkPHP的几种路由形式,分别是普通模式、PATHINFO、REWRITE和兼容模式,希望对各位学习thinkphp的朋友有帮助!

thinkphp官方文档里有详细的说明:

ThinkPHP支持的URL模式有四种:普通模式、PATHINFO、REWRITE和兼容模式,

可以设置URL_MODEL参数改变URL模式。

现在我们来总结一下这四种路由的格式:

1.普通路由(get形式路由)

htttp://localhost/?m=模块名(分组名)&c=控制器名&a=方法名&id=?

2.pathinfo路由形式(系统默认)

路由形式:http://网址/入口文件/模块名(分组名)/控制器名/方法/参数名/参数值

例如: http:// localhost/index.php/hom e/user/login/var/value/

3.REWRITE模式

REWRITE模式是在PATHINFO模式的基础上添加了重写规则的支持,可以去掉URL地

址里面的入口文件index.php,但是需要额外配置WEB服务器的重写规则。

如果是Apache则需要在入口文件的同级添加.htaccess文件,内容如下:

<IfModule mod_rewrite.c>

 RewriteEngine on

 RewriteCond %{REQUEST_FILENAME} !-d

 RewriteCond %{REQUEST_FILENAME} !-f

 RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]

</IfModule>

接下来,就可以用下面的URL地址访问了: http:// localhost/home/user/log in/var/value

4.兼容路由形式

兼容模式是用于不支持PATHINFO的特殊环境.

路由形式:http://网址/入口文件?s=/模块名(分组名)/控制器名/方法名/参数名/参数值

注意:这里的小s是兼容模式变量名称,是可以通过配置文件更改的。

以上就是ThinkPHP的几种路由形式总结的详细内容


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK