首次搭建yii项目的时候的路由是没有美化的,访问形式 www.example.com?r=site/index
    而要想使用 www.example.com/site/index 的形式访问的话,需要 美化路由
    frontend 或者 backend 对应应用下的 main.php 中打开注释的代码

    1. <?php
    2. [
    3. 'components' => [
    4. 'urlManager' => [
    5. // 路由开启美化 此为true
    6. 'enablePrettyUrl' => true,
    7. // 访问路由的时候是否带有index.php
    8. 'showScriptName' => false,
    9. 'rules' => [
    10. // ...
    11. ],
    12. ],
    13. ],
    14. ]

    还没结束,如果是 apache还需要找一份 .htaccess文件

    1. Options +FollowSymLinks
    2. IndexIgnore */*
    3. RewriteEngine on
    4. # if a directory or a file exists, use it directly
    5. RewriteCond %{REQUEST_FILENAME} !-f
    6. RewriteCond %{REQUEST_FILENAME} !-d
    7. # otherwise forward it to index.php
    8. RewriteRule . index.php