码迷,mamicode.com
首页 > Web开发 > 详细

thinkphp 学习_4中URL模式

时间:2016-06-09 13:31:54      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:

ThinkPHP有四种url模式:

0 普通模式 http://localhost/imooc/index.php?m=Index&a=user&id=1

    普通模式也就是传统的GET传参方式来指定当前访问的模块和操作,出现了m和其他页面后端取值有冲突的情况下要么 ,后端取值方式,要么改写 不同模式的命名

 ‘VAR_MODULE‘ => ‘module‘, // 默认模块获取变
 ‘VAR_CONTROLLER‘ => ‘controller‘, // 默认控制器获取变量
 ‘VAR_ACTION‘ => ‘action‘, // 默认操作获取变量

1默认模式 pathinfo模式 http://localhost/imooc/index.php/Index/user/id/1.html

   提供了最好的SEO支持,系统内部已经做了环境的兼容处理,所以能够支持大多数的主机环境:

    修改/controller/action/params.html  的分割配置 ‘URL_PATHINFO_DEPR‘=>‘-‘,

2重写模式 http://localhost/imooc/Index/user/id/1.html

   重写模式是子啊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>


3兼容模式 http://localhost/imooc/index.php?s=/Index/user/id/1.html

  兼容模式配合Web服务器重写规则的定义,可以达到和REWRITE模式一样的URL效果。

  apache的.htaccess配置写法

<IfModule mod_rewrite.c> 
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ index.php?s=/$1 [QSA,PT,L]
</IfModule>

 

thinkphp 学习_4中URL模式

标签:

原文地址:http://www.cnblogs.com/figting/p/5572238.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!