我正在尝试根据网站查看者的选择设置条件缓存重定向。
以下是我希望如何实现网站功能的示例(您可以访问 vonage.com 进行测试):
当我访问 www.vonage.com 时,我可以在“个人版、小型企业版、中端市场和企业版”之间进行选择。
做出选择后,您将被转到关联的网站/子域 - vonage.com、personal.vonage.com 或 enterprise.vonage.com。
然后,如果您尝试返回带有选择的初始页面,您将无法返回,您将被重定向回已做出的选择。
这是如何完成的?我想实现类似的东西。顺便说一句,我正在使用 Wordpress,但这可能并不重要,我可以亲自参与代码或 .htaccess。
最佳答案
可能有更好的方法,这只是java脚本而不是php,但是cookie应该可以解决问题。
在页面加载时检查 cookie 是否存在,是否重定向,如果不重定向:
if (document.cookie.indexOf("home") >= 0) {
// redirect them to home
}
else if (document.cookie.indexOf("business") >= 0) {
// redirect them to business
}
else if (document.cookie.indexOf("enterprise") >= 0) {
// redirect them to enterprise
}
如果这些都没有触发,并且用户在选择选项时不会重定向,则设置其 cookie,例如:
// set a new cookie
expiry = new Date();
expiry.setTime(date.getTime()+(10*60*1000)); // Ten minutes
// Date()'s toGMTSting() method will format the date correctly for a cookie
document.cookie = "business; expires=" + expiry.toGMTString();
关于javascript - 有条件缓存页面重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34642004/