Home  >  Article  >  PHP Framework  >  How to configure route beautification in yii

How to configure route beautification in yii

(*-*)浩
(*-*)浩Original
2019-12-30 13:46:072675browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What does yii2 log do?Next article:What does yii2 log do?