URL address beautification in Yii

Source: Internet
Author: User

URL address beautification: Urlmanager address Management (through the program to achieve the URL of the address beautification)

For example:

Original address: http://localhost/Project/app/index.php?r= Controller/method

New address: http://localhost/Project/app/index.php/Controller/method

-------------------------------

Practice:

Modify the main.php global profile to turn on the Urlmanager feature

/*

' Urlmanager ' =>array (

' Urlformat ' = ' path ',//whether to enable PathInfo mode URL address

' Rules ' =>array (//set pseudo static suffix

' <controller:\w+>/<id:\d+> ' = ' <controller>/view ',

' <controller:\w+>/<action:\w+>/<id:\d+> ' = ' <controller>/<action> ',

' <controller:\w+>/<action:\w+> ' = ' <controller>/<action> ',

),

),

*/

Remove comments

-------------------------------

Pseudo-Static

For example:

Original address: http://localhost/Project/app/index.php?r= Controller/method

New address: http://localhost/Project/app/index.php/Controller/method. html

' Urlmanager ' =>array (

' Urlformat ' = ' path ',//whether to enable PathInfo mode URL address

' Rules ' =>array (//set pseudo static suffix

' Controller alias/Method alias ' =>array ("Original controller name/original method name", "urlsuffix" = ". html"),//Add pseudo-static to the specified page

' <controller:\w+>/<action:\w+> ' =>array (' <controller>/<action> ', ' urlsuffix ' and ' = '). HTML "),//Add pseudo-static to all pages, such as with parameters, pseudo-static does not work

' Controller alias/method alias/< parameter name: Regular expression >/< parameter name: Regular expression > ' + ' original Controller name/original method name,//Set page pass parameters for the specified page

' Controller alias/method alias/< parameter name: Regular expression >/< parameter name: Regular expression > ' =>array (' original controller name/original method name ', ' urlsuffix ' = '. html '),//Set parameters for the specified page, and set pseudo-static, but only works on a single page

),

),

-------------------------------

Omit the entry file from the URL

The rewrite function must be used to achieve

URL address beautification in Yii

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.