Domanda

I'm working on mobilizing a website with the Moovweb SDK, but there are sections that I do not want to alter for mobile. How do I force these links to point to the original desktop site?

È stato utile?

Soluzione

You can do this by telling tritium that you want to change the given request into a redirect request and then redirect to the desktop website.

In mixer simple-mobile versions 1.0.224 and above, there are helper functions to do this:

redirect_temporary("www.desktop.com") # 302 redirect.
redirect_permanent("www.desktop.com") # 301 redirect.

Here's an example of a temporary redirect if the URL path contains the word "desktop" in it.

match($path) {
  with(/desktop/) {
     redirect_temporary("www.desktop.com")
  }
  else() {
    // normal transformations.
  }
}

Ideally, after calling the redirect_* function, you wouldn't execute any more tritium (there wouldn't be any point since you'll be redirecting anyways).

The one catch with this is if you've set up your load balancer at www.desktop.com to redirect to www.mobile.com if it sees a mobile user agent. If that's the case, then you'll trap yourself into an infinite redirect loop!

Bypassing this really depends on your setup and varies greatly. Though I don't know of any existing solutions to this, one experimental approach is to set a cookie on the client side with the value being the URL which you do not want redirected. If your load balancer sees this cookie, and the request path matches the value in the cookie, it avoids redirection.

If you wanted to accomplish the above scenario, you can also do this in tritium like so:

match($path) {
  with(/desktop/) {
     add_cookie("avoid_redirect", $path, "www.desktop.com")
     redirect_temporary("www.desktop.com")
  }
  else() {
    // normal transformations.
  }
}

Then in your load balancer, you'd have to check for the avoid_redirect cookie and avoid redirecting to mobile if the path in the value of the cookie is the path that is request.

Altri suggerimenti

If you still want the URL to be "m.mysite.com" the best way to do this would be through scripts/main.ts

after:

match($detected_content_type) {
  with(/html/) {

you should put in:

match($path) {
  with(/non_mobile_page_here/) {
    # do nothing!
  }
  else() {
    # put the rest of the html scope in here. 
  }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top