When responding with a HTTP 3xx Redirect status, should there still be a response body?

When responding with a HTTP 3xx Redirect status, should there still be a response body? - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the When responding with a HTTP 3xx Redirect status, should there still be a response body? error on your web browser. Problem :


When a service is answering an HTTP request with a "3xx Redirect" status code response (and the accompanying Location header) should it still send a meaningful response body along with the response?



I could imagine that maybe a page providing a link to the redirection target might be helpful if the user agent cannot handle the redirect properly, but is it even realistic to assume that this might happen? And on the other hand, sending only an empty response body might be nice opportunity to save a little bit of traffic ...



Any advise is appreciated.


Solution :

Actually I just found an answer to my own question addressed in the relevant RFC 7230 (or its predecessor RFC 2616), e.g. in the description of status code "303 See Other":



Except for responses to a HEAD request, the representation of a 303 response ought to contain a short hypertext note with a hyperlink to the same URI reference provided in the Location header field.



Essentially the same advise is given for all status codes of the 3xx family.



Answer is definitely yes to support as many web browsers as possible. There probably is one web browser out there made back in the day that someone uses that doesn't support the location header tag.



On the apache server, the standard 301 redirection message page has the following HTML code:



<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://www.website.com/">here</a>.</p>
</body></html>


and the output is Moved Permanently in large letters with "The document has moved here" underneath with the word "here" as a hyperlink to the new page.



Adding a link to a target page is used traditionally within pages that use a refresh header to redirect users. This is not optimal and not the same as a traditional 301 redirect which is transparent to the user. If you provided HTML as part of the 301 redirect, it will not likely be seen. As well, for may redirects, this opportunity does not exist such as in the case of using an .htaccess RewriteRule.


While a response body is not needed (and usually ignored by browsers), it is helpful for people who maintain links to know why a resource URL has been changed. If you put an explanation into the response body, then hopefully the people who linked to the original page will update their links.

We hope that this article has helped you resolve the redirects, http, error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

How to redirect to any domain [duplicate]

"302 found" for index page bad for SEO?

Create redirect from url like www.example.us/?p=100&option=