①  基本get形式

http://网址/index.php?m=分组&c=控制器&a=操作方法

该方式是最底层的get形式、传统的参数传递方式,不时尚、不安全。


②  pathinfo路径形式[默认方式]
http://网址/index.php/分组/控制器/操作方法

http://网址/index.php/Home/Index/advert


③  rewrite重写形式(伪静态技术)省略index.php入口文件
http://网址/分组/控制器/操作方法

http://网址/Home/Index/index


配置web服务器的重写规则

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

[html] view plain copy
  1. <IfModule mod_rewrite.c>   
[html] view plain copy
  1. RewriteEngine on   
[html] view plain copy
  1. RewriteCond %{REQUEST_FILENAME} !-d   
[html] view plain copy
  1. RewriteCond %{REQUEST_FILENAME} !-f   
[html] view plain copy
  1. RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]  
[html] view plain copy
  1. </IfModule>  
thinkphp:四种路由形式



④  兼容形式
http://网址/index.php?s=/分组/控制器/操作方法

http://网址/index.php?s=/Home/Index/advert

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

例如,我们在Apache下面的话,.htaccess文件改成如下内容:

[html] view plain copy
  1. <IfModule mod_rewrite.c>   
  2. RewriteEngine on   
  3. RewriteCond %{REQUEST_FILENAME} !-d   
  4. RewriteCond %{REQUEST_FILENAME} !-f   
  5. RewriteRule ^(.*)$ index.php?s=/$1 [QSA,PT,L]</IfModule>  
就可以和REWRITE模式一样访问的URL地址


URL模式    URL_MODEL设置   
      普通模式            0
  PATHINFO模式              1
  REWRITE模式            2
      兼容模式            3

在项目中这里配置的是重写模式(省略index.php入口文件):

thinkphp:四种路由形式


版权声明:本文为博主原创文章,未经博主允许不得转载。 http://blog.csdn.net/weixin_39768635/article/details/78196320

①  基本get形式

http://网址/index.php?m=分组&c=控制器&a=操作方法

该方式是最底层的get形式、传统的参数传递方式,不时尚、不安全。


②  pathinfo路径形式[默认方式]
http://网址/index.php/分组/控制器/操作方法

http://网址/index.php/Home/Index/advert


③  rewrite重写形式(伪静态技术)省略index.php入口文件
http://网址/分组/控制器/操作方法

http://网址/Home/Index/index


配置web服务器的重写规则

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

[html] view plain copy
  1. <IfModule mod_rewrite.c>   
[html] view plain copy
  1. RewriteEngine on   
[html] view plain copy
  1. RewriteCond %{REQUEST_FILENAME} !-d   
[html] view plain copy
  1. RewriteCond %{REQUEST_FILENAME} !-f   
[html] view plain copy
  1. RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]  
[html] view plain copy
  1. </IfModule>  
thinkphp:四种路由形式



④  兼容形式
http://网址/index.php?s=/分组/控制器/操作方法

http://网址/index.php?s=/Home/Index/advert

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

例如,我们在Apache下面的话,.htaccess文件改成如下内容:

[html] view plain copy
  1. <IfModule mod_rewrite.c>   
  2. RewriteEngine on   
  3. RewriteCond %{REQUEST_FILENAME} !-d   
  4. RewriteCond %{REQUEST_FILENAME} !-f   
  5. RewriteRule ^(.*)$ index.php?s=/$1 [QSA,PT,L]</IfModule>  
就可以和REWRITE模式一样访问的URL地址


URL模式    URL_MODEL设置   
      普通模式            0
  PATHINFO模式              1
  REWRITE模式            2
      兼容模式            3

在项目中这里配置的是重写模式(省略index.php入口文件):

thinkphp:四种路由形式


相关文章:

  • 2021-06-23
  • 2022-01-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2020-03-28
  • 2022-12-23
  • 2022-12-23
  • 2021-06-21
  • 2022-12-23
  • 2021-12-20
相关资源
相似解决方案