yii2的url重寫方法

1.首先保證開啓apache的rewrite 模塊

2.開啓分佈式配置文件AllowOverride All

3.在index.php同級目錄下,創建 .htaccess 文件。寫入一下內容
1
Options +FollowSymLinks
2
IndexIgnore */*
3
RewriteEngine on
4
 
5
# if a directory or a file exists, use it directly
6
RewriteCond %{REQUEST_FILENAME} !-f
7
RewriteCond %{REQUEST_FILENAME} !-d
8
 
9
# otherwise forward it to index.php
10
RewriteRule . index.php
 4.在Yii2中配置:frontend/config/main.php
1
'urlManager'=>[
2
    'class' => 'yii\web\UrlManager',    //指定實現類
3
    'enablePrettyUrl' => true,    // 開啓URL美化
4
    'showScriptName' => false, // 是否顯示index.php
5
    'suffix' => '.html',    // 僞靜態後綴
6
    'rules'=>[
7
        // 自定義路由規則
8
     ],
9
],
配置好後訪問方式    http://yii.com/user/add.html
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章