Welcome to Example.ai

HTTP Redirections

Redirections with HTTP is used to send client requests to alternate servers, web pages, applications, or forms.

HTTP response codes are used not only to indicate the failure or success of a HTTP request but also, to provide information to the client on how to proceed. One such example is the HTTP 3xx response code category, which indicates an HTTP redirection and is also known as URL forwarding.

  • URL forwarding
  • Temporary versus permanent redirections
  • Available HTTP redirect status codes
  • Temporary redirections
    • 302 Found
    • 303 See Other
    • 307 Temporary Redirect
    • 301 Moved Permanently
    • 308 Permanent Redirect
    • 300 Multiple Choices
    • 304 Not Modified
    • 305 Use Proxy
    • 306 Switch Proxy
    • Apache
    • PHP
    • Non-System Specific
      • Mandatory Secure HTTP
      • Broadening Scope
      • Changing Domains
      • Meta redirections
      • JavaScript redirection
      • Crypto redirection

      URL forwarding

      An HTTP redirect is used for a variety of reasons, some of which include accommodating resources that have moved either temporarily or permanently. A temporary redirect might be used during a period of site maintenance, or during an outage, whereas a permanent redirect is used when the URL is changing forever.

      HTTP responses that include HTTP redirection status codes also contain the HTTP Location response header to inform the client of the new URL for the resource. When a web browser receives this type of HTTP response, it immediately loads the resource that is indicated by the Location header.

      Temporary versus permanent redirections

      A temporary redirection is intended to last for a short time, such as to accommodate for an outage or while the main site is undergoing maintenance. Available temporary redirects are 302 Found, 303 See Other and 307 Temporary Redirect.

      A permanent redirection is intended to last forever, meaning that the former URL is not to be used again. Available permanent redirects are 301 Moved Permanently and 308 Permanent Redirect.

      The distinction between temporary and permanent requests is important, in part, because of how they are indexed by search engines. Specifically, when a redirection is permanent then it is prudent for an search engine to modify the stored URL and reduce crawling of the old URL while refocusing crawling and indexing efforts on the newer URL. However, if a resource is only moved temporarily then leaving it as-is will avoid having to correct it again in the presumably near future while search engines keep crawling both variations.

      If you need assistance with SEO and redirects, contact ex-Google SEO consultants Search Brothers.

      Available HTTP redirect status codes

      Temporary redirections

      When a temporary redirect is served for a prolonged period of time, search engines may reassess how to handle the redirect response and change its status to permanently redirected within their own indexes and act accordingly going forward.

      302 Found

      The HTTP 302 Found redirect message indicates that the requested resource has been temporarily moved and that a second, otherwise identical HTTP request will be made to fetch the resource. The original specification did not intend for clients to change the type of HTTP request method; however, to accommodate situations where this was implemented, this redirection type does not force clients to preserve the HTTP request method.

      In situations where the server intends something more specific, it has the option to return HTTP 303 See Other or HTTP 307 Temporary Redirect to remove ambiguity.

      303 See Other

      The HTTP 303 See Other redirect message indicates that the result of the HTTP request is viewable at an alternate Location, which can be accessed using a GET method. This differs from HTTP 302 Found because the post-redirect fetch request must be HTTP GET, which may or may not be the same HTTP method as the original HTTP request.

      An example use case is after a user has filled out a form, a redirection to a textual resource, accessed using HTTP GET, can inform the client that the form has been successfully submitted.

      307 Temporary Redirect

      The HTTP 307 Temporary Redirect message indicates that the result of the HTTP request is viewable at an alternate Location, and it will be accessed using the same HTTP request method used for the original HTTP request. The 307 Temporary Redirect status code was created because clients were often treating HTTP response 302 Found as if it were HTTP response 303 See Other.

      Permanent redirections

      301 Moved Permanently

      The HTTP 301 Moved Permanently redirect message indicates that the resource has moved to a new URL that is specified within the HTTP response. Clients and caching servers need to update their internal data to reflect the new Location and no longer use the original URL.

      Similar to HTTP 302 Found, HTTP response status code 301 Moved Permanently allows clients to change the HTTP request method when fetching the resource post-redirect. For example, if the original HTTP request is an HTTP POST then the client is permitted to use HTTP GET for the post-redirect follow-up HTTP request.

      308 Permanent Redirect

      The HTTP 308 Permanent Redirect redirect message indicates that the resource has moved to a new URL that is specified within the HTTP response with the Location header. Clients need to update their internal data accordingly and when making the follow-up HTTP request, they are not permitted to change the HTTP request method.

      Special redirections

      A special redirection occurs for reasons other than the moving of a resource. There are only two special redirections: 300 Multiple Choices and 304 Not Modified.

      300 Multiple Choices

      HTTP response 300 Multiple Choices is returned by the server to indicate that more than one HTTP response is available as a result of the HTTP request. It indicates success, although it is the client’s responsibility to select which of the presented options best fits their requirements.

      304 Not Modified

      HTTP response 304 Not Modified is returned by the server to indicate a successful HTTP request, yet the client already has the most recent version of the resource stored in its cache. The HTTP redirection , in this context, is redirected to the client’s internal cache.

      Deprecated or not used

      305 Use Proxy

      The HTTP 305 Use Proxy redirect message indicates that the HTTP request needs to be made through a proxy, and specifies the Location where a subsequent, identical HTTP request shall be made. However this HTTP response has been deprecated and as such, is not to be used.

      306 Switch Proxy

      The 306 Switch Proxy is a status code that is not currently used and has been reserved for future use. It was originally intended to instruct a client to use an alternative proxy to retrieve the requested resource.

      Examples

      Apache

      Setting up the Apache webserver for redirects can be defined in the .htaccess file as follows:

      # Redirects the root path (often different hostname) to https://example.ai/ Redirect 302 / https://example.ai/ 
      # Redirects any request for https://example.ai/index.html to https://example.ai/ Redirect 301 /index.html https://example.ai/ 
      # Redirects any pattern in https://example.ai/old/ to the same files # in the https://example.ai/new/ subdirectory. RewriteEngine On RewriteRule ^old/(.*)$ /new/$1 [R=301,NC,L] 

      PHP

      Shorter version of permanent redirect

      Non-System Specific

      Independent of the server or client that is being used, these more general examples are typical of where HTTP redirections are employed.

      Mandatory Secure HTTP

      Redirecting HTTP requests from an HTTP version of a page to an HTTPS version will enforce usage of the secure version, as long as the scheme is supported by the client.

      Broadening Scope

      Simple mapping to help users more easily find a website. For example, the main site is located at:

      However users may request the hostname without the www-subdomain, also known as the naked-domain name, and the user can then be redirected from the alternate hostname to the main hostname:

      Changing Domains

      From time to time, such as when a website is given a new name, domain names may change. In these cases, redirecting all of the resources to the new domain name assists users as well as search engines with finding the new domain name.

      HTTP redirection alternatives

      Although HTTP redirection is the standard approach to redirecting clients to an alternate URL, webmasters do not always have that degree of control over the server. Alternatives include using meta , JavaScript and crypto redirection.

      Meta redirections

      In the following example, the meta element is used with the http-equiv attribute set to refresh . This will cause the browser to redirect the client to the specified URL. The content attribute specifies the URL and the number of seconds to wait before the redirect happens.

      With the content attribute set to zero, the redirect is not delayed and search engines interpret this as a permanent redirect. If the content attribute is set to a nonzero value then the redirect will be delayed and search engines will interpret this as a temporary redirect.

      JavaScript redirection

      In order to effect a redirection using JavaScript, a URL string is to set the window.location property. This forces the specified page to load.

      In the following example, the window.location property is to the new URL of the resource.

             .  

      Crypto redirection

      Crypto redirection is an old descriptive name for what is nowadays is more often referred to as a soft 404, where the URL responds with a 200 OK status code and a link to the new URL with an explanatory message that the content has moved to a new location.

      Redirection precedence

      In the event that multiple redirects are included, HTTP redirection are given the highest priority. This type of redirect is available even in cases where there is no page data transmitted. The second priority is given to HTML redirects that use the meta element. The third priority is given to JavaScript redirection, but only when JavaScript is enabled and executed. Finally, crypto redirection takes the lowest priority.

      Infinite redirection loops

      If a server is set up incorrectly, or the client has data corruption in its cookies or cache, it can lead to a situation where circular loops exist. These can sometimes be detected by the server, which may then return the HTTP 500 Internal Server Error status code. However, if there are many servers involved and no single device has enough information to make this determination, some browsers are able to detect this and present the user with an error on the client-side. Clearing cookies and the browser cache may solve the redirection loop if the cause is due to data corruption on the client-side.

      Takeaway

      When a client attempts to retrieve a resource from a URL where the resource is no longer hosted, either permanently or on a temporary basis, a redirect is used to inform the client of the proper location.

      HTTP Status Tester

      Test live and from different countries the HTTP responses, redirect chains and status codes of one or multiple URLs.

      1. HTTP/0.9
      2. HTTP/1.0
      3. HTTP/1.1
      4. HTTP/2
      5. HTTP/3
      6. HTTP Authentication
      7. HTTP Caching
      8. Client Hints
      9. HTTP Compression
      10. HTTP Conditional Requests
      11. HTTP Content Negotiation
      12. HTTP Cookies
      13. Cross-Origin Resource Sharing (CORS)
      14. Data URLs
      15. HTTP Explained
      16. HTTP Headers
      17. HTTP Strict Transport Security
      18. HTTP Connection
      19. HyperText Transfer Protocol Secure (HTTPS)
      20. HyperText Transfer Protocol (HTTP)
      21. HTTP Methods
      22. Origins
      23. Percent-Encoding
      24. HTTP Protocol Upgrade Mechanism
      25. Punycode
      26. HTTP Range Request
      27. A typical HTTP session
      28. Soft 404s
      29. HTTP Status Codes
      30. Uniform Resource Identifier (URI)
      31. Uniform Resource Locator (URL)
      32. Uniform Resource Name (URN)
      33. WebDAV
      34. WebSocket
      35. Encrypted WebSocket

      Made with ♥ by SEO Expert Fili © 2022 — 2023 Licensed under CC BY-NC-ND 4.0

      Источник

      Читайте также:  Java stream join to string
Оцените статью