Yii2的urlManager URL美化

1.在Nginx中开启rewrite 
server {
        listen       80;
        server_name  new.com ;
        location / {
            root   F:/www/new/web;
            index  index.html index.htm index.php;
            #autoindex  on;
             if (!-e $request_filename){
                rewrite ^/(.*) /index.php?r=$1 last;
            }
        }
        location ~ \.php$ {
            root          F:/www/new/web;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
}

 2.config中web.php 配置
'urlManager' => [
            'enablePrettyUrl' => true,  //美化url==ture
            'enableStrictParsing' => false,  //不启用严格解析 
            'showScriptName' => false,   //隐藏index.php
            'rules' => [
                '<module:\w+>/<controller:\w+>/<id:\d+>' => '<module>/<controller>/view',
                '<controller:\w+>/<id:\d+>' => '<controller>/view',
            ],
        ]

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章