简体   繁体   English

受缓存影响的移动浏览器上奇怪的网站重定向问题

[英]Strange website redirect issue on mobile browser that's influenced by cache

I'm at a loss here. 我在这里茫然。

I have a new Wordpress site at synergration.com. 我在synergration.com上有一个新的Wordpress网站。

If you access it on a mobile device (phone, not tablet) it will generally load fine the first time. 如果您在移动设备(电话,而不是平板电脑)上访问它,通常会在第一次加载时正常加载。 Once you click on to another page and/or reload the home page it jumps into a redirect loop indefinitely attempting to reload the same page over and over and over... 一旦单击另一个页面和/或重新加载主页,它就会无限次跳入重定向循环,并一遍又一遍地尝试重新加载同一页面...

I've weeded through the code and have been unable to find any JS redirects. 我已经遍历了代码,无法找到任何JS重定向。 I've also contacted the theme developer and they've been unable to help. 我还联系了主题开发人员,他们一直无法提供帮助。

This only became an issue when I started hosting on WP Engine. 当我开始在WP Engine上托管时,这才成为问题。 They use some advanced caching that seems to be the culprit here as when I test the mobile site on their staging server (where no cacheing exists) it loads fine. 他们使用一些高级缓存,这似乎是罪魁祸首,因为当我在他们的登台服务器(不存在缓存)上测试移动站点时,它可以很好地加载。

I contacted WPEngine about it and this was their reply: 我就此联系了WPEngine,这是他们的回复:

This is being caused by our caching systems that run on our platform. 这是由我们在平台上运行的缓存系统引起的。 It looks like the theme is handling an internal redirect that detects the user agent (desktop or mobile) and redirects the visitor to the appropriate site based on that information. 看起来主题正在处理内部重定向,该重定向检测到用户代理(台式机或移动代理),并根据该信息将访问者重定向到适当的站点。 However, the redirect is getting stuck in cache, causing the mobile version to load in an infinite loop. 但是,重定向被卡在缓存中,导致移动版本以无限循环加载。 Unfortunately, we don't have an easy solution for this. 不幸的是,我们对此没有简单的解决方案。 If this were only one part of the site, we could just exempt that part of the site from caching, but because it covers the whole site, exempting from caching isn't an option. 如果这只是站点的一部分,我们可以使站点的该部分免于缓存,但是由于它覆盖了整个站点,因此不能选择不进行缓存。 Our staging area is exempt from all caching, which is why it's working normally there. 我们的暂存区域不受所有缓存的影响,这就是为什么它可以在那里正常工作。 (The old host was most-likely using a non-cached environment, which is why you didn't see this issue there). (旧主机最有可能使用的是非缓存环境,这就是为什么您在此处未看到此问题的原因)。 I would contact the theme developer and ask them if they've ever come across this issue before. 我将与主题开发人员联系,并询问他们是否曾经遇到过此问题。 There's a good chance they have, and they might have a clever solution as a work-around. 他们有很大的机会,而且他们可能会有一个聪明的解决方案。 You might have the option of disabling the mobile routing, which would solve the redirect issue, though mobile devices would load the full version of the site rather than the slimmed-down mobile version. 您可以选择禁用移动路由,这将解决重定向问题,尽管移动设备将加载站点的完整版本,而不是精简的移动版本。

As noted above, the theme developer didn't have any solution and I'm back at square one so I figured I'd reach out to stack to see if ya'll had any ideas. 如上所述,主题开发人员没有任何解决方案,我回到了第一广场,所以我认为我可以伸出手来看看您是否有任何想法。

It works absolutely fine in my mobile's Opera Mini browser. 在我的手机的Opera Mini浏览器中,它绝对可以正常工作。 To answer your question, an alternative way is to just create a mobile subdomain, like m.yourdomain.com. 要回答您的问题,另一种方法是只创建一个移动子域,例如m.yourdomain.com。 Make this decision public and let mobile users know in advance that that is the site for mobile users. 将此决定公开,并让移动用户提前知道这是移动用户的网站。 A specific mobile site is loads better than visiting the page and then being redirected. 特定的移动网站的加载比访问页面然后被重定向更好。 It also saves time. 这也节省了时间。

While developing the mobile site, keep in mind, to use minimal JavaScript. 在开发移动网站时,请记住要使用最少的JavaScript。 The reason being, that older mobile versions may not support JavaScript and if JavaScript is essential then it becomes a big problem. 原因是,较早的移动版本可能不支持JavaScript,如果必须使用JavaScript,那么这将成为一个大问题。

Speaking about the theme, if it is getting stuck and developer has no idea, so the best option, FOR NOW, is change the template. 说到主题,如果主题卡住了并且开发人员不知道,那么最好的选择是立即更改模板。 Let the developer inspect on his very code. 让开发人员检查他的代码。 You can by that time use another template, that'll keep the site up running well whether it is on Mobile or anything. 到那时,您可以使用另一个模板,无论它是在Mobile上还是在其他任何地方,都可以使网站正常运行。 Because, small errors can divert lot of traffic from your site. 因为,小错误可以转移大量网站流量。 I, to be frank, have no idea about what caching problems WP is having, and I don't expect anyone here to be knowing that, so it really depends on time. 坦率地说,我不知道WP遇到了什么缓存问题,而且我不希望这里的任何人都知道这一点,所以这实际上取决于时间。 Till then, as I said, do try to use some other template for the time-being. 就像我说的那样,到那时,一定要尝试使用其他模板作为时间。

All the best. 祝一切顺利。

I have two sites on WP Engine with redirect. 我在WP Engine上有两个带有重定向的站点。 They are identical gensis child themes and redirect plugins. 它们是相同的gensis子主题和重定向插件。 I have one setup with a DNS redirect to a cname record for a "M.sitename.com" URL and the other redirecting to the mobile site that is having the same issue you noted above. 我有一个设置,其中DNS重定向到“ M.sitename.com” URL的cname记录,另一个设置重定向到您遇到上述相同问题的移动网站。 I haven't had an issue with the site that points to the cname record. 我对指向cname记录的网站没有任何疑问。 I am about the change the other site to the cname configuration to see if it makes a difference. 我打算将另一个站点更改为cname配置,以查看是否有所作为。 I have no ideal why this works, but thought you might find this of value. 我不认为这行得通,但我想您可能会觉得有价值。

I faced similar issue recently. 我最近也遇到了类似的问题。 It took good amount of time but I finally figured it out. 花了很多时间,但我终于弄明白了。

To prevent redirect from caching, you have to use 302 redirect. 为了防止重定向缓存,您必须使用302重定向。 Moreover, you have initialize this redirect in "template_redirect" action of wordpress. 此外,您已经在wordpress的“ template_redirect”操作中初始化了此重定向。 If you do it in like "init", it'll be cache too. 如果像“ init”那样执行,它也会被缓存。

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

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