About Yii2 URL beautification and related Apache configuration issues

Source: Internet
Author: User
about Yii2 's URL beautification

We may encounter this problem when writing a YII2 project: Http://frontend.hyii2.com/index.php?r=site/about
We will think this URL is not beautiful, want to change to http://frontend.hyii2.com/site/about this form, which involves the routing configuration (URL beautification problem)
For example, we configure the foreground URL, we need to add a redirect file under the \frontend\web folder, that is. htaaccess, the file contents are as follows

Rewriteengine

 on # If it is a directory or a file, access the directory or file
 rewritecond%{request_filename}!-d

 # If the file exists, directly access the file, Do not perform the following rewriterule
 rewritecond%{request_filename}!-f


 rewriterule. index.php

Next configure the server, I use Apache here, open the Apache configuration file (httpd.conf file in the apache\conf directory)
1. Open the Apache mod_rewrite module

Remove LoadModule rewrite_module modules/mod_rewrite.so before the "#" symbol; modify Apache's allowoverride

Change allowoverride None to allowoverride all;

Be sure to restart the server after the configuration is complete. Otherwise it won't take effect .
After the configuration is completed, add Urlmanager to the project file, as shown below


Hide Portal script: Showscriptname = False
Route routing: Enableprettyurl = True
If you want to add. html to add ' suffix ' + '. html '

Save the page when you are done, and then open the URL. If there is a 404 error, check the contents of the file carefully, and place the correct location.

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.