ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • HTTP Redirect
    개발/Web 2022. 6. 14. 19:26

    *복습 자료라서 뻔한 내용은 생략

     

     

    Summary.

     

    1. URL redirection, also known as URL forwarding, is a technique to give more than one URL address to a page, a form, or a whole Web site/application. HTTP has a special kind of response, called a HTTP redirect, for this operation

    • Temporary redirects during site maintenance or downtime
    • Permanent redirects to preserve existing links/bookmarks after changing the site's URLs, progress pages when uploading a file, etc.

     

    2. In HTTP, redirection is triggered by a server sending a special redirect response to a request. Redirect responses have status codes that start with 3, and a Location header holding the URL to redirect to

        + When browsers receive a redirect, they immediately load the new URL provided in the Location header. Besides the small performance hit of an additional round-trip, users rarely notice the redirection

    3. 3종류 Redirection

        + Permanant Redirection: These redirections are meant to last forever. They imply that the original URL should no longer be used, and replaced with the new one. Search engine robots, RSS readers, and other crawlers will update the original URL for the resource

        + Temporary Redirection: Sometimes the requested resource can't be accessed from its canonical location, but it can be accessed from another place. In this case, a temporary redirect can be used. Search engine robots and other crawlers don't memorize the new, temporary URL. Temporary redirections are also used when creating, updating, or deleting resources, to show temporary progress pages

        + Special Redirection: 304 (Not Modified) redirects a page to the locally cached copy (that was stale), and 300 (Multiple Choice) is a manual redirection: the body, presented by the browser as a Web page, lists the possible redirections and the user clicks on one to select it

     

    4. HTTP redirects aren't the only way to define redirections. There are two others:

    1. HTML redirections with the <meta> element
    2. JavaScript redirections via the DOM
    <head>
      <meta http-equiv="Refresh" content="0; URL=https://example.com/">
    </head>

        + HTTP redirects are the best way to create redirections, but sometimes you don't have control over the server

        + The content attribute should start with a number indicating how many seconds the browser should wait before redirecting to the given URL. Always set it to 0 for accessibility compliance. Obviously, this method only works with HTML, and cannot be used for images or other types of content

        + javascript redirection:

    window.location = "https://example.com/";

     

    5. Order of Precedence

    1. HTTP redirects always execute first — they exist when there is not even a transmitted page.
    2. HTML redirects (<meta>) execute if there weren't any HTTP redirects.
    3. JavaScript redirects execute last, and only if JavaScript is enabled

     

    6. Use cases

        + Domain Aliasing

            ex) A common case is when a site resides at www.example.com, but accessing it from example.com should also work. Redirections for example.com to www.example.com are thus set up. You might also redirect from common synonyms or frequent typos of your domains

            ex) For example, your company was renamed, but you want existing links or bookmarks to still find you under the new name

            ex) Requests to the http:// version of your site will redirect to the https:// version of your site

        + Unsafe Request Redirection: Typically, you don't want your users to resend PUT, POST or DELETE requests. If you serve the response as the result of this request, a simple press of the reload button will resend the request (possibly after a confirmation message). In this case, the server can send back a 303 (See Other) response for a URL that will contain the right information. If the reload button is pressed, only that page is redisplayed, without replaying the unsafe requests

        + Keeping links alive

        + Temporary responses to long requests: Some requests may need more time on the server, like DELETE requests that are scheduled for later processing. In this case, the response is a 303 (See Other) redirect that links to a page indicating that the action has been scheduled, and eventually informs about its progress, or allows to cancel it

     

     

    7. Redirection Loop 조심할 것

     

     

    Reference.

    '개발 > Web' 카테고리의 다른 글

    HTTP Range Request  (0) 2022.06.14
    HTTP Compression  (0) 2022.06.14
    HTTP Caching  (0) 2022.06.14
    HTTP Authentication  (0) 2022.06.12
    Web Security  (0) 2022.06.12
Designed by Tistory.