Redirect mobile nginx

0

I'm having a problem doing a redirect.

It's for me to put www.mysite.com/default/true and it directs me to the normal site even though I'm on my cell phone.

if ($http_user_agent ~* "(android|bb\d+|meego).+mobile|android|jasmine|minimo|mot|MOT|nokia|sonyericsson|webos|avantgo|bada/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)/|plucker|pocket|psp|series(4|6)0|symbian|treo|up.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino") {
     set $mobile_rewrite perform;
        }

set $force_dt_cookie "";

if ($args ~ 'desktop=true') { set $mobile_rewrite do_not_perform; set $force_dt_cookie "desktop=true"; }

add_header Set-Cookie $force_dt_cookie;

if ($http_cookie ~ 'desktop=true') { set $mobile_rewrite do_not_perform; }

    if ($mobile_rewrite = perform) {
            rewrite ^ http://m.meusite.com.br$request_uri? redirect;
            break;
    }

Has anyone ever experienced this?     
asked by anonymous 03.12.2014 / 14:41

1 answer

0

I have already experienced this problem, but in your case you detect the mobile device with:

if ($http_user_agent ~* "(android|bb\d+|meego).+mobile|android|jasmine|minimo|mot|MOT|nokia|sonyericsson|webos|avantgo|bada/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)/|plucker|pocket|psp|series(4|6)0|symbian|treo|up.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino") {
     set $mobile_rewrite perform;
        }

This is correct but at the end instead of forwarding to the www if you detected the mobile you are targeting the mobile with the domain m that is usually associated with mobile devices:

if ($mobile_rewrite = perform) {
            rewrite ^ http://m.meusite.com.br$request_uri? redirect;
            break;
    }

To go to www.mysite.com as you wish you should do:

if ($mobile_rewrite = perform) {
                rewrite ^ http://www.meusite.com.br$request_uri? redirect;
                break;
        }

This assuming that this configuration you are indicating is the one that has server_name www.mysite.com in nginx.

    
23.09.2015 / 12:29