Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Update 2014-Jun-27</strong>: </p> <p><a href="http://tools.ietf.org/html/rfc7231" rel="noreferrer">RFC 7231, Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content</a>, has been published as a PROPOSED STANDARD. From the <a href="http://tools.ietf.org/html/rfc7231#appendix-B" rel="noreferrer">Changelog</a>:</p> <blockquote> <p>The syntax of the Location header field has been changed to allow all URI references, including relative references and fragments, along with some clarifications as to when use of fragments would not be appropriate. (Section 7.1.2)</p> </blockquote> <p>The important points from <a href="http://tools.ietf.org/html/rfc7231#section-7.1.2" rel="noreferrer">Section 7.1.2. Location</a>:</p> <blockquote> <p>If the Location value provided in a 3xx (Redirection) response does not have a fragment component, a user agent MUST process the redirection as if the value inherits the fragment component of the URI reference used to generate the request target (i.e., the redirection inherits the original reference's fragment, if any).</p> <p>For example, a GET request generated for the URI reference "<a href="http://www.example.org/~tim" rel="noreferrer">http://www.example.org/~tim</a>" might result in a 303 (See Other) response containing the header field:</p> <pre><code>Location: /People.html#tim </code></pre> <p>which suggests that the user agent redirect to "<a href="http://www.example.org/People.html#tim" rel="noreferrer">http://www.example.org/People.html#tim</a>"</p> <p>Likewise, a GET request generated for the URI reference "<a href="http://www.example.org/index.html#larry" rel="noreferrer">http://www.example.org/index.html#larry</a>" might result in a 301 (Moved Permanently) response containing the header field:</p> <pre><code>Location: http://www.example.net/index.html </code></pre> <p>which suggests that the user agent redirect to "<a href="http://www.example.net/index.html#larry" rel="noreferrer">http://www.example.net/index.html#larry</a>", preserving the original fragment identifier.</p> </blockquote> <p>This should clearly answer your questions.</p> <p><strong>Update END</strong></p> <p>this is an open (not specified) issue with the <a href="http://tools.ietf.org/html/rfc2616" rel="noreferrer">current HTTP specification</a>. it is addressed in 2 issues of the <a href="http://www.ietf.org/dyn/wg/charter/httpbis-charter.html" rel="noreferrer">IETF httpbis working group</a>:</p> <ul> <li><a href="http://trac.tools.ietf.org/wg/httpbis/trac/ticket/6" rel="noreferrer">#6: <em>Fragments allowed in Location</em></a></li> <li><a href="http://trac.tools.ietf.org/wg/httpbis/trac/ticket/43" rel="noreferrer">#43: <em>Fragment combination / precedence during redirects</em></a></li> </ul> <p>#6 allows fragments in the <code>Location</code> header. #43 says this:</p> <blockquote> <p>I just tested this with various browsers.</p> <ul> <li>Firefox and Safari use the fragment in the location header.</li> <li>Opera uses the fragment from the source URI, when present, otherwise the fragment from the redirect location</li> <li>IE (8) ignores the fragment in the location URI, thus will use the fragment from the source URI, when present</li> </ul> <p>Proposal:</p> <p>"Note: the behavior when fragment identifiers from the original URI and the redirect need to be combined is undefined; current User Agents indeed differ on what fragment takes precedence."</p> <p>[...]</p> <p>It appears that IE8 <em>does</em> use the fragment idenfitier from <code>Location</code> (the behavior I saw might be limited to localhost).</p> <p>Thus we seem to have consistent behavior for Safari/IE/Firefox/Chrome (just tested), in that the fragment from the Location header gets used, no matter what the original URI was.</p> <p>I therefore change my proposal to document <em>that</em> as expected behavior.</p> </blockquote> <p>this leads to the most browser compatible and future proof (because this issue will eventually get standardized) answer to your question:</p> <p><strong>A:</strong> fragments from original URLs get discarded.</p> <p><strong>B:</strong> fragments from the <code>Location</code> header are honored.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload