简体   繁体   中英

MoovWeb: Redirect desktop user to desktop site if they try to visit m.site.com

Using MoovWeb for a large eCommerce client. They want to block desktop users from visiting the mobile site. So basically, if a user is using a desktop browser and tries to visit (m.site.com) they will be redirected to (site.com).

Must do this in Tritium (most likely near the top of main.ts), because by the time JS runs, we'd be loading the site twice (once in m. then once again in www.)

I'm hesitant to go the route of using Regex to check $user_agent, because if we don't match EVERY POSSIBLE mobile agent, and the user goes to m. on their unmatched phone , they will get an endless redirect (m. > www. > m. > www. > m. > ...). I know there are very detailed Regex strings for user agents, however as detailed as they are, the only way we would find out that some phone out there is no longer matched is through loss of sales, which is not an option.

Here was my original Tritium test attempt, which causes redirect for mobile users that don't use Android or iPhone:

match($host,/^m\./) {
    match($user_agent) {
        not(/(Android|iPhone)/) {
            $newHost = $host
            $newHost {
                replace(/^m\./,"")
            }
            $redirect = "http://"+$newHost+$path
            export("Location",$redirect)
        }
    }
}

Moovweb provides redirection both client side and server side out-of-the-box. It's recommended that you implement server-side redirection which has the least amount of roundtrips.

Here is the official documentation: https://moovwebconfluence.atlassian.net/wiki/display/DD/Mobile+Redirection#MobileRedirection-Server-SideRedirection

Best,

Juan C.

    match($host,/m./) {
            $newHost = $host
            $newHost {
                replace(/m./,"www.")
            }
            $redirect = "http://"+$newHost+$path
            export("Location",$redirect)
        }

Try this. Hope this will work you as this worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM