How to access URL in thinkPHP5.0 framework
Jun 08, 2018 am 09:56 AM这篇文章主要介绍了thinkPHP5.0框架URL访问方法,具体分析了thinkPHP5.0框架的URL路径结构与常见访问方法,以及隐藏入口文件的实现技巧,需要的朋友可以参考下
本文实例讲述了thinkPHP5.0框架URL访问方法。分享给大家供大家参考,具体如下:
URL设计
ThinkPHP5.0在没有启用路由的情况下典型的URL访问规则是:
http://serverName/index.php(或者其它应用入口文件)/模块/控制器/操作/[参数名/参数值...]
支持切换到命令行访问,如果切换到命令行模式下面的访问规则是:
>php.exe index.php(或者其它应用入口文件) 模块/控制器/操作/[参数名/参数值...]
可以看到,无论是URL访问还是命令行访问,都采用PATH_INFO访问地址,其中PATH_INFO的分隔符是可以设置的。
注意:5.0取消了URL模式的概念,并且普通模式的URL访问不再支持,如果不支持PATHINFO的服务器可以使用兼容模式访问如下:
http://serverName/index.php(或者其它应用入口文件)?s=/模块/控制器/操作/[参数名/参数值...]
必要的时候,我们可以通过某种方式,省略URL里面的模块和控制器。
URL大小写
默认情况下,URL是不区分大小写的,也就是说 URL里面的模块/控制器/操作名会自动转换为小写,控制器在最后调用的时候会转换为驼峰法处理。
例如:
http://localhost/index.php/Index/Blog/read
// 和下面的访问是等效的
http://localhost/index.php/index/blog/read
如果访问下面的地址
http://localhost/index.php/Index/BlogTest/read
// 和下面的访问是等效的
http://localhost/index.php/index/blogtest/read
在这种URL不区分大小写情况下,如果要访问驼峰法的控制器类,则需要使用:
http://localhost/index.php/Index/blog_test/read
如果希望URL访问严格区分大小写,可以在应用配置文件中设置:
// 关闭URL中控制器和操作名的自动转换 'url_convert' => false,
一旦关闭自动转换,URL地址中的控制器名就变成大小写敏感了,例如前面的访问地址就要写成:
http://localhost/index.php/Index/BlogTest/read
但是下面的URL访问依然是有效的:
http://localhost/index.php/Index/blog_test/read
下面的URL访问则无效:
http://localhost/index.php/Index/blogtest/read
需要注意:路由规则中定义的路由地址是按照控制器名的实际名称定义(区分大小写)。
隐藏入口文件
在ThinkPHP5.0中,出于优化的URL访问原则,还支持通过URL重写隐藏入口文件,下面以Apache为例说明隐藏应用入口文件index.php的设置。
下面是Apache的配置过程,可以参考下:
1、httpd.conf配置文件中加载了mod_rewrite.so模块
2、AllowOverride None 将None改为 All
3、在应用入口文件同级目录添加.htaccess文件,内容如下:
<IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] </IfModule>
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!
相关推荐:
用ThinkPHP5实现作业管理系统中学生未交作业与已交作业信息的处理方法
The above is the detailed content of How to access URL in thinkPHP5.0 framework. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel

Simplified HTTP Response Mocking in Laravel Tests

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

Build a React App With a Laravel Back End: Part 2, React

12 Best PHP Chat Scripts on CodeCanyon
