Yii2_nginx怎样实现url重写

发布时间:2021-11-15 15:54:30 作者:柒染
来源:亿速云 阅读:254

这篇文章给大家介绍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重写就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

推荐阅读:
  1. Nginx URL重写(rewrite)配置及信息详解
  2. Nginx如何实现URL重写规则配置

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

nginx yii url

上一篇:centos 7.0如何实现网卡配置及重命名

下一篇:怎么解决服务器跨域问题

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》