ThinkPHP5.0 framework URL access method details, thinkphp5.0url

Source: Internet
Author: User

ThinkPHP5.0 framework URL access method details, thinkphp5.0url

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
// It 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
// It is equivalent to the following access
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:

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

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.