Sharing thinkPHP5.0 framework URL access methods

Source: Internet
Author: User
This article mainly introduces the thinkPHP5.0 framework URL access method, analyzes the URL path structure and common access methods of the thinkPHP5.0 framework, as well as the implementation skills of hiding the Portal file, for more information about how to access thinkPHP5.0 framework URL, see the next article. I have analyzed the URL path structure and common access methods of thinkPHP5.0 framework, as well as the implementation skills for hiding Portal files, for more information, see

This article describes the thinkPHP5.0 framework URL access method. We will share this with you for your reference. The details are as follows:

URL design

The typical URL access rule for ThinkPHP5.0 is:

Http: // serverName/index. php (or other application entry File)/module/controller/operation/[parameter name/parameter value...]

You can switch to the command line access mode. if you switch to the command line mode, the following access rules are:

> Php.exe index. php (or other application entry files) module/controller/operation/[parameter name/parameter value...]

We can see that both URL access and command line access use The PATH_INFO access address, where the PATH_INFO separator can be set.

Note:5.0 the concept of URL mode is removed, and URL access in normal mode is no longer supported. if the server does not support PATHINFO, access in compatible mode is allowed.As follows:

Http: // serverName/index. php (or other application entry files )? S =/module/controller/operation/[parameter name/parameter value...]

When necessary, we can omit the modules and controllers in the URL in some way.

URL case

By default, the URL is case-insensitive. that is to say, the module/controller/operation name in the URL is automatically converted to lower case, and the controller is converted to the hump method during the final call.

For example:

Http: // localhost/index. php/Index/Blog/read // is equivalent to the following access: http: // localhost/index. php/index/blog/read

If you access the following address

Http: // localhost/index. php/Index/BlogTest/read // the following access is equivalent to http: // localhost/index. php/index/blogtest/read

If the URL is case insensitive and you want to access the controller class of the hump method, you need to use:

http://localhost/index.php/Index/blog_test/read

If you want URL access to be case sensitive, you can set it in the application configuration file:

// Disable automatic conversion of controllers and Operation names in URLs 'URL _ convert' => false,

Once automatic conversion is disabled, the controller name in the URL address becomes case sensitive. for example, the previous access address must be written:

http://localhost/index.php/Index/BlogTest/read

However, the following URL access is still valid:

http://localhost/index.php/Index/blog_test/read

The following URL access is invalid:

http://localhost/index.php/Index/BlogTest/read

Note: the routing address defined in the routing rule is based on the actual name of the controller name (case sensitive ).

Hide the entry file

In ThinkPHP5.0, to optimize the URL access principle, you can also rewrite the hidden entry file using the URL. the following uses Apache as an example to describe how to hide the index. php setting of the application entry file.

The configuration process of Apache is as follows:

1. the mod_rewrite.so module is loaded in the httpd. conf configuration file.
2. change AllowOverride None to All
3. add the. htaccess file in the same directory of the application entry file. the content is as follows:

 
  Options +FollowSymlinks -MultiviewsRewriteEngine onRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
 

The above is the details shared by the thinkPHP5.0 framework URL access method. For more information, see other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.