简体   繁体   English

在Tritium中,如何强制链接转到桌面站点?

[英]In Tritium, how can I force a link to go to the desktop site?

I'm working on mobilizing a website with the Moovweb SDK, but there are sections that I do not want to alter for mobile. 我正在使用Moovweb SDK来动员网站,但是有些部分我不想更改以用于移动设备。 How do I force these links to point to the original desktop site? 如何强制这些链接指向原始桌面站点?

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. 您可以通过告诉Tritium您要将给定请求更改为重定向请求,然后重定向到桌面网站来完成此操作。

In mixer simple-mobile versions 1.0.224 and above, there are helper functions to do this: 在混音器简单移动版本1.0.224及更高版本中,有一些辅助功能可以做到这一点:

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. 如果URL路径中包含单词“ desktop”,则这是一个临时重定向的示例。

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). 理想情况下,在调用redirect_ *函数之后,您将不再执行任何tri(不会有任何意义,因为无论如何都将进行重定向)。

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. 遇到的一个问题是,如果您在www.desktop.com上设置了负载均衡器,并在看到移动用户代理后将其重定向到www.mobile.com。 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. 尽管我不知道有任何现有的解决方案,但是一种实验性的方法是在客户端设置cookie,其值为您不希望重定向的URL。 If your load balancer sees this cookie, and the request path matches the value in the cookie, it avoids redirection. 如果您的负载平衡器看到此cookie,并且请求路径与cookie中的值匹配,则它将避免重定向。

If you wanted to accomplish the above scenario, you can also do this in tritium like so: 如果您想完成上述情况,则也可以像这样在t中执行此操作:

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. 然后,在负载平衡器中,如果Cookie值中的路径是请求的路径,则必须检查prevent_redirect cookie并避免重定向到mobile。

If you still want the URL to be "m.mysite.com" the best way to do this would be through scripts/main.ts 如果您仍然希望URL为“ m.mysite.com”,则最好的方法是通过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. 
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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