当前位置:网站首页>详解ThinkPHP支持的URL模式有四种普通模式、PATHINFO、REWRITE和兼容模式
详解ThinkPHP支持的URL模式有四种普通模式、PATHINFO、REWRITE和兼容模式
2022-07-07 10:37:00 【全栈程序员站长】
URL模式 URL_MODEL设置 普通模式
0 PATHINFO模式 1 REWRITE模式 2 兼容模式 3
如果你整个应用下面的模块都是采用统一的URL模式,就可以在应用配置文件中设置URL模式,如果不同的模块需要设置不同的URL模式,则可以在模块配置文件中设置。
普通模式
普通模式也就是传统的GET传参方式来指定当前访问的模块和操作,例如: http://localhost/?m=home&c=user&a=login&var=value m参数表示模块,c参数表示控制器,a参数表示操作(当然这些参数都是可以配置的),后面的表示其他GET参数。 如果默认的变量设置和你的应用变量有冲突的话,你需要重新设置系统配置,例如改成下面的:
‘VAR_MODULE’ => ‘module’, // 默认模块获取变量 ‘VAR_CONTROLLER’ => ‘controller’, // 默认控制器获取变量 ‘VAR_ACTION’ => ‘action’, // 默认操作获取变量
上面的访问地址则变成: http://localhost/?module=home&controller=user&action=login&var=value
注意,VAR_MODULE只能在应用配置文件中设置,其他参数可以则也可以在模块配置中设置
PATHINFO模式
PATHINFO模式是系统的默认URL模式,提供了最好的SEO支持,系统内部已经做了环境的兼容处理,所以能够支持大多数的主机环境。对应上面的URL模式,PATHINFO模式下面的URL访问地址是: http://localhost/index.php/home/user/login/var/value/ PATHINFO地址的前三个参数分别表示模块/控制器/操作。 不过,PATHINFO模式下面,依然可以采用普通URL模式的参数方式,例如: http://localhost/index.php/home/user/login?var=value 依然是有效的 PATHINFO模式下面,URL是可定制的,例如,通过下面的配置:
// 更改PATHINFO参数分隔符
‘URL_PATHINFO_DEPR’=>’-‘,
我们还可以支持下面的URL访问: http://localhost/index.php/home-user-login-var-value REWRITE模式
REWRITE模式是在PATHINFO模式的基础上添加了重写规则的支持,可以去掉URL地址里面的入口文件index.php,但是需要额外配置WEB服务器的重写规则。 如果是Apache则需要在入口文件的同级添加.htaccess文件,内容如下:
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*) index.php/1 [QSA,PT,L]
接下来,就可以用下面的URL地址访问了: http://localhost/home/user/login/var/value
更多环境的URL重写支持参考部署部分的URL重写。
兼容模式
兼容模式是用于不支持PATHINFO的特殊环境,URL地址是: http://localhost/?s=/home/user/login/var/value 可以更改兼容模式变量的名称定义,例如:
‘VAR_PATHINFO’ => ‘pathinfo’
PATHINFO参数分隔符对兼容模式依然有效,例如:
// 更改PATHINFO参数分隔符
‘URL_PATHINFO_DEPR’=>’-‘,
使用以上配置的话,URL访问地址可以变成: http://localhost/?s=/home-user-login-var-value 兼容模式配合Web服务器重写规则的定义,可以达到和REWRITE模式一样的URL效果。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/113484.html原文链接:https://javaforall.cn
边栏推荐
- How much does it cost to develop a small program mall?
- Financial data acquisition (III) when a crawler encounters a web page that needs to scroll with the mouse wheel to refresh the data (nanny level tutorial)
- Several ways to clear floating
- Static vxlan configuration
- 【从 0 开始学微服务】【02】从单体应用走向服务化
- 【PyTorch实战】图像描述——让神经网络看图讲故事
- BGP third experiment report
- Realize a simple version of array by yourself from
- Simple implementation of call, bind and apply
- 【从 0 开始学微服务】【01】什么是微服务
猜你喜欢
SQL lab 26~31 summary (subsequent continuous update) (including parameter pollution explanation)
【统计学习方法】学习笔记——支持向量机(上)
SQL Lab (46~53) (continuous update later) order by injection
基于NeRF的三维内容生成
SQL Lab (36~40) includes stack injection, MySQL_ real_ escape_ The difference between string and addslashes (continuous update after)
Pule frog small 5D movie equipment | 5D movie dynamic movie experience hall | VR scenic area cinema equipment
Several ways to clear floating
Charles: four ways to modify the input parameters or return results of the interface
Zhimei creative website exercise
普乐蛙小型5d电影设备|5d电影动感电影体验馆|VR景区影院设备
随机推荐
Experiment with a web server that configures its own content
Polymorphism, final, etc
[crawler] avoid script detection when using selenium
Static routing assignment of network reachable and telent connections
AirServer自动接收多画面投屏或者跨设备投屏
Processing strategy of message queue message loss and repeated message sending
The hoisting of the upper cylinder of the steel containment of the world's first reactor "linglong-1" reactor building was successful
[play RT thread] RT thread Studio - key control motor forward and reverse rotation, buzzer
聊聊Redis缓存4种集群方案、及优缺点对比
Solutions to cross domain problems
File upload vulnerability - upload labs (1~2)
Master formula. (used to calculate the time complexity of recursion.)
Static vxlan configuration
Configure an encrypted web server
【从 0 开始学微服务】【00】课程概述
Day-16 set
ACL 2022 | 序列标注的小样本NER:融合标签语义的双塔BERT模型
【深度学习】图像多标签分类任务,百度PaddleClas
【二叉树】删点成林
【PyTorch实战】用RNN写诗