urlManager

url设置为这种样子

http://localhost/advanced/frontend/web/index.php/site/index
  • 在man.php增加
'urlManager' => [
         //让URL更漂亮
          'enablePrettyUrl' => true,
        ],
  • 如果你想自定义url别名books访问talk/index
    http://localhost/advanced/frontend/web/index.php/talk/index
    http://localhost/advanced/frontend/web/index.php/books
'urlManager' => [
          'enablePrettyUrl' => true,
           //定义路由别名访问
          'rules'=>[
            'books'=>'talk/index'
            ]
        ],

http://localhost/advanced/frontend/web/index.php/talk/index

'urlManager' => [
          'enablePrettyUrl' => true,
          'enableStrictParsing' => true,
          'rules'=>[
            'books'=>'talk/index'
            ]
        ],

Example routes

Url::to(['']) - /index.php/site/routes
Url::to(['about']) - /index.php/site/about
Url::to(['about/details']) - /index.php/about/details
Url::to(['/book/index']) - /index.php/books
Url::to(['book/view','id'=>2]) - /index.php/book/view?id=2
Url::to(['book/view','id'=>2,'#'=>'contnt']) - /index.php/book/view?id=2#content
Url::to(['/book/index'],true) - http://yii2.test/index.php/books
Url::to(['/book/index'],'https') - https://yii2.test/index.php/books

Aliases
Yii::setAlias('@books','/book/index');
Url::to([@books]) - /index.php/book/index;

你可能感兴趣的:(urlManager)