![](/img/trans.png)
[英]How can I get the anchor (#tag) from an <a> link in tritium?
[英]In Tritium, how can I force a link to go to the desktop site?
我正在使用Moovweb SDK來動員網站,但是有些部分我不想更改以用於移動設備。 如何強制這些鏈接指向原始桌面站點?
您可以通過告訴Tritium您要將給定請求更改為重定向請求,然后重定向到桌面網站來完成此操作。
在混音器簡單移動版本1.0.224及更高版本中,有一些輔助功能可以做到這一點:
redirect_temporary("www.desktop.com") # 302 redirect.
redirect_permanent("www.desktop.com") # 301 redirect.
如果URL路徑中包含單詞“ desktop”,則這是一個臨時重定向的示例。
match($path) {
with(/desktop/) {
redirect_temporary("www.desktop.com")
}
else() {
// normal transformations.
}
}
理想情況下,在調用redirect_ *函數之后,您將不再執行任何tri(不會有任何意義,因為無論如何都將進行重定向)。
遇到的一個問題是,如果您在www.desktop.com上設置了負載均衡器,並在看到移動用戶代理后將其重定向到www.mobile.com。 如果是這種情況,那么您將陷入無限的重定向循環中!
繞過這個問題確實取決於您的設置,並且差異很大。 盡管我不知道有任何現有的解決方案,但是一種實驗性的方法是在客戶端設置cookie,其值為您不希望重定向的URL。 如果您的負載平衡器看到此cookie,並且請求路徑與cookie中的值匹配,則它將避免重定向。
如果您想完成上述情況,則也可以像這樣在t中執行此操作:
match($path) {
with(/desktop/) {
add_cookie("avoid_redirect", $path, "www.desktop.com")
redirect_temporary("www.desktop.com")
}
else() {
// normal transformations.
}
}
然后,在負載平衡器中,如果Cookie值中的路徑是請求的路徑,則必須檢查prevent_redirect cookie並避免重定向到mobile。
如果您仍然希望URL為“ m.mysite.com”,則最好的方法是通過scripts/main.ts
后:
match($detected_content_type) {
with(/html/) {
您應該輸入:
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.