The relationship between the PathInfo mode of Thinkphp 3.2 and controller

Source: Internet
Author: User
Tags file url

There are four modes of pathinfo:

0: Normal mode is the traditional get method to specify which modules and operations are currently accessed, for example:

Http://localhost/?m=home&c=user&a=login&var=value

The M parameter represents the module, the C parameter represents the controller, the A parameter represents the operation (of course these parameters are configurable), and the other get parameters are later represented.

If the default variable settings conflict with your application variables, you will need to reset the system configuration, for example, to the following:

' Var_module ' = ' module  ',     //The default module gets the variable ' var_controller ' = ' controller ',//The default controllers get variable ' var_action ' = > ' action ',//default action get variable

The above access address becomes:

http://localhost/?module=home&controller=user&action=login&var=value

1:pathinfo mode , it is divided into two modes below. The default access mode is Http://bbs.aaa.net/index.php/user/index

pathinfo Mode is the system default mode , provides the best SEO support, the system has already done the environment compatibility processing, so can support most host environment. Corresponding to the URL pattern above, the URL access address under PathInfo mode is:http://localhost/index.php/home/user/login/var/value/    PATHINFO地址的前三个参数分别表示模块/控制器/操作。  

However, under the PathInfo mode, you can still use the normal URL mode parameter, for example: http://localhost/index.php/home/user/login?var=value still valid

Under PathInfo mode, URLs are customizable, for example, through the following configuration:

    1. // 更改PATHINFO参数分隔符
    2. ‘URL_PATHINFO_DEPR‘=>‘-‘,

We can also support the following URL access:http://localhost/index.php/home-user-login-var-value


2:rewrite rewrite (pseudo-static). you can write the relevant rewrite rules yourself, or you can use the rewrite rules that the system provides for us. Http://bbs.aaa.net/user/index.

One of the Apache manuals is a URL rewrite rule that you can look at.

Rewrite mode is based on the PathInfo mode to add support for rewrite rules, you can remove the URL address inside the entry file index.php, but need to configure additional Web server rewrite rules.

Implement rewrite

1.Apache you will need to add the. htaccess file to the same sibling of the portal file with the following

<ifmodule mod_rewrite.c>    rewriteengine    on%{request_filename}-d    %{request_ FILENAME}-F    ^ (. *) $ index.php/$1 [qsa,pt,L]</IfModule>

The Mod_rewrite.so module (remove the previous #) is loaded in the httpd.conf configuration file in the 2.Apache configuration file, and then allowoverride none changes to None

3. Change the file URL mode to rewrite mode in the project's configuration file

' Url_model ' = 2,

4. Restart Apache
3: compatibility mode . is for a special environment that does not support pathinfo, the URL address is:http://localhost/?s=/home/user/login/var/value

You can change the name definition of a compatible mode variable, for example:

' Var_pathinfo ' = '  PATHINFO '

The PathInfo parameter delimiter is still valid for compatibility mode, for example:// 更改PATHINFO参数分隔符

' Url_pathinfo_depr ' = '-',

With the above configuration, the URL access address can be changed to:http://localhost/?s=/home-user-login-var-value

Compatibility mode, in conjunction with the definition of a Web server rewrite rule, can achieve the same URL effect as rewrite mode.

For example, if we are under Apache, the. htaccess file is changed to the following:

<ifmodule mod_rewrite.c>    rewriteengine    on%{request_filename}-d    %{request_ FILENAME}-F    ^ (. *) $ index.php?s=/$1 [qsa,pt,L]</IfModule>

You can access the following URL address in the same way as the rewrite mode:http://localhost/home/user/login/var/value

The relationship between the PathInfo mode of Thinkphp 3.2 and controller

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.