HTTPのLocationについて。

パスだけじゃダメって覚えていたのですが、だいぶ前にパスだけでもよくなってたんですね、っていう。

RFC 2616 – Hypertext Transfer Protocol — HTTP/1.1

For 3xx responses, the location SHOULD indicate the server’s preferred URI for automatic redirection to the resource. The field value consists of a single absolute URI.

RFC 7231 – Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content

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).

なんでこんなことを書いているかというと、Railsでredirect_toには_pathではなく_urlを使うっていう癖がついてまして。
最近「_urlを使うのはなぜですか?」という質問を受け、調べ直した次第です。
こんな感じで無意識でやってること、他にもありそう。

タイトルとURLをコピーしました