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.