Is a 302 redirect to relative URL valid, or invalid?

HttpRedirect

Http Problem Overview


Based on the RFC it seems like the Location field in an HTTP response for a 302 should be absolute. https://www.rfc-editor.org/rfc/rfc2616#section-14.30

If this statement is correct, do browsers honor this - or do they allow relative paths?

Http Solutions


Solution 1 - Http

RFC 2616 requires an absolute URI in the Location, but that standard has been replaced, since June 2014. The relevant specification is now RFC 7231. The relevant section of the new standard says:

> Location = URI-reference

> The field value consists of a single URI-reference. When it has the form of a relative reference ([RFC3986], Section 4.2), the final value is computed by resolving it against the effective request URI ([RFC3986], Section 5).

So a relative URI is now permitted. The effective request URI is the same as the request URI in most cases.

Solution 2 - Http

Relative URLs are valid.

There is a bug in RFC 2616. See <http://greenbytes.de/tech/webdav/draft-ietf-httpbis-p2-semantics-17.html#rfc.section.9.5>;.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGeorgeUView Question on Stackoverflow
Solution 1 - HttpRaedwaldView Answer on Stackoverflow
Solution 2 - HttpJulian ReschkeView Answer on Stackoverflow