7

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.

9

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.

1
  • I may be slow... but one up-vote is well deserved! – closetnoc Feb 14 '15 at 2:03
3

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.

2

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.

2
  • I agree, it will not likely be seen. I was just wondering whether I missed some practical use for status 3xx response bodies. I will go with my service not sending response bodies for redirects. – MRA Feb 5 '15 at 10:01
  • Actually, after reading the RFCs I just changed my mind. :) See this answer for the reasons: webmasters.stackexchange.com/a/77189/49242 – MRA Feb 13 '15 at 10:39
2

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.

2

AdBlock or some other plugin was causing some redirects not to happen automatically for me in my browser. This normally wasn't a problem because the redirect usually includes a page with something to click on. There were a few redirect services that didn't include the page and it was annoying.

Most users will never see that content, but there are occasions in which it is useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.