Can I send an HTTP redirect to a URL with an anchor?

Is it possible to send a response with status code 302 to a URL, for example:

http://mysite.com/something/#somethingelse

+5
source share
5 answers

Following the HTTP specification, the value for the header field must be an absolute URI value. And this is according to RFC 3986 (they just changed the name from absoluteURI to absolute URI): Location

absolute-URI  = scheme ":" hier-part [ "?" query ]

Thus, in theory, a fragment is not allowed as part of a value. But browsers can handle this.

+5
source

Yes, you can use the fragment identifier. This is a known bug in the HTTP specification.

. http://trac.tools.ietf.org/wg/httpbis/trac/ticket/6.

+4

RFC2616 , URI. , IETF HTTP .

Julian , URI ( HTML-) Location: http://www.greenbytes.de/tech/tc2231/redirects.html

, ist: , URI .

+3

, PHP:

Header(
    "Location: http://en.wikipedia.org/wiki/HTTP#Status_codes",
    true,
    302
);
+2

. , , .

+1

All Articles