302 重定向会保留引用字符串吗? [英] Will a 302 redirect maintain the referer string?

查看:12
本文介绍了302 重定向会保留引用字符串吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将用户从一个页面重定向到另一个页面,但我需要维护原始引用字符串.因此,例如,如果他们开始于 http://www.othersite.com/pageA.jsp,单击将他们带到 http://www.example.com/pageB.jsp 的链接,然后执行 302 重定向到 http://www.example.com/pageC.jsp,我需要引用字符串包含http://www.othersite.com/pageA.jsp

I need to redirect the user from one page to another, but I need to maintain the original referer string. So, for example, if they start out on http://www.othersite.com/pageA.jsp, click a link that takes them to http://www.example.com/pageB.jsp, which then executes a 302 redirect to http://www.example.com/pageC.jsp, I need the referer string to contain http://www.othersite.com/pageA.jsp

这是 302 重定向的正常行为吗?或者我的原始引用会被删除,转而使用 http://www.example.com/pageB.jsp?这是不可取的.

Is this the normal behavior for a 302 redirect? Or would my original referer get dropped, in favor of http://www.example.com/pageB.jsp? That would not be desirable.

我不知道这是否有什么不同,但我在 JSP 中工作,我正在使用 response.sendRedirect() 来执行 302 重定向.

I don't know if it makes any difference, but I'm working in JSP, and I'm using response.sendRedirect() to execute the 302 redirect.

我应该提到我对此做了一个实验,它似乎保留了原始引用字符串(http://www.othersite.com/pageA.jsp)但我只是想要以确保这是正常的默认行为,而不是我这边的奇怪行为.

I should mention that I did an experiment with this, and it seems to have kept the original referer string (http://www.othersite.com/pageA.jsp) but I just wanted to make sure this was the normal default behavior, and not something weird on my end.

虽然我目前使用的是 302 重定向,但我可能会改用 301 重定向.你知道 301 重定向的行为是否更可靠?

Although I'm currently using a 302 redirect, I could probably use a 301 redirect instead. Do you know if the behavior for 301 redirects is any more reliable?

推荐答案

简短的回答是它没有在相关的 RFC 2616 http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.36 用于 Referer 标头或 302 状态代码.

Short answer is it's not specified in the relevant RFC 2616 http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.36 either for the Referer header or the 302 status code.

最好的办法是使用多个浏览器进行测试,看看是否存在共识行为.

Your best bet is to do a test with several browsers and see if there's a consensus behaviour.

对于完整的腰带和括号,请在重定向 URL 中编码原始引荐来源网址,以便您可以保证检索到它.

For full belt and braces, encode the original referrer in the redirect URL so you can guarantee to retrieve it.

这篇关于302 重定向会保留引用字符串吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆