这篇文章给大家介绍Yii2_nginx怎样实现url重写,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
'urlManager' => [ //'urlFormat' => 'path', 'class'=>'yii\web\UrlManager', 'enablePrettyUrl' => true, 'showScriptName' => false,//false 表示隐藏index.php 'rules'=>[ "/cn.html"=>"/cn/tv/index", "/<id:\w+>/{0,1}"=>"/tv/cate", "/cn/<id:\w+>/{0,1}"=>"/cn/tv/cate", "/tv/<id:(.*)>.html"=>"/tv/detail", "/cn/tv/<id:(.*)>.html"=>"/cn/tv/detail", ] ],
下面是nginx 的配置
server { listen 80; server_name www.xx.com xxx.com; root /www/xx/web; index index.php index.html index.htm; location / { index index.html index.php; if (!-e $request_filename){ rewrite ^/(.*) /index.php last; } } if ($host != 'www.xx.com') { rewrite ^/(.*)$ https://www.xxx.com/$1 permanent; } if ($http_x_forwarded_proto != "https"){ rewrite ^/(.*)$ https://$host/$1 permanent; } location ~ \.php(.*)$ { fastcgi_pass php:9000; include fastcgi-php.conf; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } server { listen 443; server_name www.xx.com; root /www/xx/web; index index.php index.html index.htm; ssl on; ssl_certificate /ssl/www.xx.com/xx.pem; ssl_certificate_key /ssl/www.xx.com/xxx.key; location / { index index.html index.php; if (!-e $request_filename){ rewrite ^/(.*) /index.php last; } } location ~ \.php(.*)$ { fastcgi_pass php:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi-php.conf; include fastcgi_params; } }
这样配置即可
关于Yii2_nginx怎样实现url重写就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。