将用户从旧网站重定向到新网站时,检测是否向他们显示自定义欢迎消息的最佳方法是什么?

发布于 2024-07-15 21:05:57 字数 916 浏览 2 评论 0 原文

假设您有一个旧网站,在提供某些功能的旧代码库上运行。 后续网站已启动并运行,提供所有旧功能及更多功能。 一段时间以来,旧网站上有一个指向新网站的 HTML 链接,供那些愿意点击的用户使用。

现在,旧网站即将寿终正寝,您希望自动将用户重定向到新网站,例如通过 301 或 302 重定向。 但是,当用户遇到此重定向时,您还希望在新网站上显示一条友好的消息欢迎他们并解释为什么他们看不到旧版本。

当用户单击 HTML 链接时,将填充 HTTP_REFERER 标头,并且可以通过该值触发欢迎消息。 然而,使用 3XX 重定向代码时,情况似乎并非如此。

谷歌针对这个问题的热门搜索是这样说的: “HTTP 1.1 规范明确规定:如果给出 3XX 代码,则不 Referer 值已传递。 (最终,指向 3XX 站点的 URL)。” (http://www .usenet-forums.com/apache-web-server/37811-how-set-referer-redirect.html#post145986

但是,我在快速阅读规范时找不到此声明(https://www.rfc-editor.org/rfc/rfc2616)。

谁能建议实现此功能的正确方法?

注意:这并不意味着是一个包罗万象的解决方案。 我们知道,出于隐私原因,某些客户端甚至不发送 HTTP_REFERER 标头,但为了便于讨论,让我们忽略该用例。

Say you have a legacy website running on an old code-base that offers certain functionality. The successor website is up and running, providing all the old functionality and more. For some time, there has been an HTML link on the old site pointing to the new one, for those users that care to click over.

Now, the legacy site is reaching its end of life, and you want to automatically redirect users to the new site, for example via a 301 or 302 redirect. However, when a user encounters this redirect, you want to also display a friendly message on the new site welcoming them and explaining why they are not seeing the old version.

When the user clicks an HTML link, the HTTP_REFERER header is populated, and the welcome message can be triggered via that value. However it appears that the same is not true when using 3XX redirect codes.

The top Google hit for this issue has this to say:
"HTTP 1.1 specification states it clearly: if a 3XX code is given, no
Referer value is passed. (eventualy, the URL that pointed to 3XX site)."
(http://www.usenet-forums.com/apache-web-server/37811-how-set-referer-redirect.html#post145986)

However I could not find this statement in a quick read through the spec (https://www.rfc-editor.org/rfc/rfc2616).

Can anyone suggest the proper way to achieve this functionality?

Note: This is not meant to be an all-encompassing solution. We understand that some clients don't even send the HTTP_REFERER header for privacy reasons, but for the sake of argument, let's ignore that use case.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

等待圉鍢 2024-07-22 21:05:57

首先,这应该是 301,而不是 302 重定向。 您的重定向是永久性的,因此您需要表明这一点。 至于如何表示重定向,只需在url中添加一个parm即可。 不要重定向到 http://www.newsite.com 将其重定向到 http://www.newsite.com?FromOldSite=Y

First, This should be a 301, not a 302 redirect. Your redirection is permanent, so you want to indicate that. As to how to indicate the redirect, just add a parm to the url. Instead of redirecting to http://www.newsite.com redirect them to http://www.newsite.com?FromOldSite=Y

暮年 2024-07-22 21:05:57

您能否将它们重定向到特定的启动页面? 就像尝试访问 http://oldsite.com/desired/page 一样,只需将它们发送到 http://newsite.com/welcome?nextpage=/desired/page代码>. 欢迎页面可以显示消息,然后将其传递给内容。 或者,您可以通过 URL 中的 ?show_welcome=true 将它们直接发送到新页面。

Could you just redirect them to a specific launch page? Like if try try to visit http://oldsite.com/desired/page, just send them to http://newsite.com/welcome?nextpage=/desired/page. The welcome page could show the message and then pass them over to the content. Alternatively, you could send them right to the new page with a ?show_welcome=true in the URL.

夏见 2024-07-22 21:05:57

不确定您打算如何重定向用户,但如果您不想“丑化”您的 URL,您可以在访问旧网站时设置自己的自定义标头,然后在新网站上检查它。

Not sure how you plan to redirect your users, but if you don't want to "ugly" up your URL, you might just set your own custom header when hitting the old site and then check for it at the new.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文