The access address of the YII framework, if not simplified, can be cumbersome, and the simplified address general format is as follows:
Http://localhost:80/test/index.php?r=xxx/xxx/xxx
It can be more complicated with parameters:
Http://localhost:80/test/index.php?r=xxx/xxx/xxx¶m1=XXX¶m2=XXX
So how do we beautify it:
1. In the Config folder under the main.php file, find the configuration of Urlmanager, modified as follows:
' Urlmanager ' =>array (
' Urlformat ' => ' path ',
' Rules ' =>array (
' <controller:\w+>/<id:\d+> ' => ' <controller>/view ',
' <controller:\w+>/<action:\w+>/<id:\d+> ' => ' <controller>/<action> ',
' <controller:\w+>/<action:\w+> ' => ' <controller>/<action> ',
' <controller:\w+>/<action:\w+> ' => ' <controller>/<action> ',
),
),
Now to visit your project, you will find that your project URL becomes:
Http://localhost:80/test/index.php/XXX/XXX
2. This and not enough, we want to continue to simplify, the index.php also removed. Continue to modify the main.php file,
' Urlmanager ' =>array (
' Urlformat ' => ' path ',
' Showscriptname ' =>false,//Remove index.php
' Urlsuffix ' => '. html ',//Plus. html
' Rules ' =>array (
' <controller:\w+>/<id:\d+> ' => ' <controller>/view ',
' <controller:\w+>/<action:\w+>/<id:\d+> ' => ' <controller>/<action> ',
' <controller:\w+>/<action:\w+> ' => ' <controller>/<action> ',
' <controller:\w+>/<action:\w+> ' => ' <controller>/<action> ',
),
),
After this modification, index.php disappeared, but found that part of the URL error. How to solve it.
3. Add the. htaccess file for access to the project. The contents are as follows:
<ifmodule mod_rewrite.c>
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
Rewriterule. index.php
</IfModule>
This entry will automatically access the index.php file, the URL will not be garbled.
The last simplified URL is as follows:
Http://localhost:80/test/XXX/XXX