Home > Article > PHP Framework > How to configure route beautification in yii
Beautify the routing form
For example: localhost/index.php?r=site/index Recommended learning: yii tutorial)
This routing form is not friendly to SEO, so can the routing be beautified? In Yii2, we can change the routing into the following form:
For example: localhost/index.php/sie/index
This routing form is the same as what we see in the browser address bar Most routing forms are the same
get. When passing parameters, you only need to pass ?
after routing.
For example: localhost/index .php/site/index?id=1
yii’s routing beautification work is solely responsible for the urlManager component.
By default, this component is not enabled. We simply configure it in the configuration file backend\config\main.php.
enablePrettyUrl: Whether to enable the beautification effect.
To achieve the simplification of the above routing, you need to configure UrlManage in the Yii2 configuration and add the following configuration in main.php:
'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ ], ],
The above is the detailed content of How to configure route beautification in yii. For more information, please follow other related articles on the PHP Chinese website!