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

查看:58
本文介绍了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中指定

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天全站免登陆