Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

redirect

http

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?

like image 406
GeorgeU Avatar asked Nov 23 '11 23:11

GeorgeU


People also ask

How does a 302 redirect work?

A 302 redirect does not pass the “juice,” or keep your domain authority to its new location. It simply redirects the user to the new location for you so they don't view a broken link, a 404 not found page, or an error page.

Does browser automatically redirect 302?

Does a 302 automatically redirect? Yes. Since the browser is handling the communication between the server and you, it will automatically redirect to the new resource location. However, the same communication will occur with the new resource, too.

What is a 302 link?

The HyperText Transfer Protocol (HTTP) 302 Found redirect status response code indicates that the resource requested has been temporarily moved to the URL given by the Location header.


1 Answers

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.

like image 198
Raedwald Avatar answered Sep 19 '22 08:09

Raedwald