nginx: redirect mobile requests to /mobile/$uri

后端 未结 3 1248
轮回少年
轮回少年 2021-02-09 18:00

I am trying to setup my nginx to redirect all the requests from mobile devices to /mobile/$uri i came up with this solution but it doesn\'t seem to work. Is it a syntax problem

3条回答
  •  北恋
    北恋 (楼主)
    2021-02-09 18:41

        #initliaze mobile
        set $mobile "";
    
        if ($request_uri !~* "^/mobile.*" ){
            set $mobile Y;
        }
        if ($http_user_agent ~* (iPhone|iPod|android|blackberry) ) {
            set $mobile "${mobile}E";
        }
    
        if ( $http_referer !~* "xxx\.org" ){
           set $mobile "${mobile}S";
        }
    
        if ( $host ~* "xxx\.org" ){
           set $mobile "${mobile}S";
        }
    
        if ($mobile = YESS){
            rewrite ^ $scheme://$host/mobile$request_uri ;
        }
    

提交回复
热议问题