网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

Yii2_nginx怎样实现url重写

这篇文章给大家介绍Yii2_nginx怎样实现url重写,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

创新互联长期为近千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为荥阳企业提供专业的成都做网站、成都网站设计,荥阳网站改版等技术服务。拥有十多年丰富建站经验和众多成功案例,为您定制开发。

'urlManager' => [
            //'urlFormat' => 'path',
            'class'=>'yii\web\UrlManager',
            'enablePrettyUrl' => true,
            'showScriptName' => false,//false 表示隐藏index.php
            'rules'=>[
                "/cn.html"=>"/cn/tv/index",
                "//{0,1}"=>"/tv/cate",
                "/cn//{0,1}"=>"/cn/tv/cate",
                "/tv/.html"=>"/tv/detail",
                "/cn/tv/.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重写就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。


标题名称:Yii2_nginx怎样实现url重写
分享网址:http://bjjierui.cn/article/pcsdoj.html

其他资讯