我目前为一般缓存等设置 Varnish,但也充当我们网站移动版本的重定向。
它工作得很好(就像 Varnish 一样!)并按预期重定向。我决定向 VCL 配置添加功能,不仅将手机重定向到网站的移动版本,而且还将访问移动网站链接的桌面(例如,在 Google 上)重定向到网站的桌面版本。
但是,我似乎无法以最令人费解的方式让它发挥作用。这是VCL:
# 忽略某些共享资源 if (req.url !~ ".(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|css)$") {
# Let's detect if we're a Mobile
if (req.http.User-Agent ~ "iP(hone|od)" || req.http.User-Agent ~ "Android" || req.http.User-Agent ~ "Symbian" || req.http.User-Agent ~ "^BlackBerry" || req.http.User-Agent ~ "^SonyEricsson" || req.http.User-Agent ~ "^Nokia" || req.http.User-Agent ~ "^SAMSUNG" || req.http.User-Agent ~ "^LG" || req.http.User-Agent ~ "webOS" || req.http.User-Agent ~ "^PalmSource") {
# If we're a mobile, set the X-Device header.
set req.http.X-Device = "mobile";
# If we've not set a preference to the fullsite to override the redirect, and we're not accessing the mobile site, redirect. This all works fine.
if ((req.http.Cookie !~ "fullsite")&&(req.url !~ "mobile")){
error 750 "Moved Temporarily";
}
}
else{
# We're not mobile. I can see this header is set in the logs.
set req.http.X-Device = "desktop";
# If we're a desktop AND accessing the mobile site....
if (req.url ~ "mobile"){
# -------------------- THIS NEVER HAPPENS
error 750 "Moved Temporarily";
}
}
}
这里的逻辑有明显的错误吗?我可以看到没有任何 cookie 或任何其他可能干扰重定向的东西。如果有人对此有任何见解,我将永远感激不尽:)最好的问候B