Yii2 simple address beautify and hide index.php

Source: Internet
Author: User

Purpose: I just want to get rid of the index.php?r= in the browser address bar.

Add the following code to the ' components ' =>[ in/config/web.php:

1' Urlmanager ' = [2' Enableprettyurl ' =true,3' Showscriptname ' =false,//Hide index.php4 //' enablestrictparsing ' = False,5' Suffix ' = '. html ',//suffix, if this is set, then the browser address bar must be brought with an. html suffix, or 404 error will be reported6' Rules ' = [7                 //' <controller:\w+>/<action:\w+> ' = ' <controller>/<action> ',8],9],

If you have changed the suffix this look, be sure to add the. html to the path of the browser's address bar.

Changed the above, I found that ? r= This piece can be used / instead of access, but want to hide index.php or not.

We also need to add the. htaccess file under the index.php sibling directory:

Open Notepad and enter the following code:

Options +followsymlinks    indexignore */*    rewriteengine on    # If a directory or a file exists, use it directly
   rewritecond%{request_filename}!-f    rewritecond%{request_filename}!-d    # Otherwise forward it to index.php< C9/>rewriterule. index.php

It is then saved in the same directory as the portal file index.php, which is the/web directory, and the file name is filled in. htaccess, Files of type select All Files (*. *) , and then save.

The final Test is OK!

Yii2 simple address beautify and hide index.php

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.