To modify the 301 redirect HTML body of NGINX
September 14, 2020 02:57AM
Could if be possible to change the 301 redirect HTML body of nginx?

I know it sounds really presomptuous. so, let's dive into the deep.

So, when you perform the following:

jojo@DESKTOP-IRG1A6S:~$ curl
<head><title>301 Moved Permanently</title></head>
<center><h1>301 Moved Permanently</h1></center>

In June 2014, RFC7231 from IETF mentionned that:

The server SHOULD generate a Location header field in the response
containing a preferred URI reference for the new permanent URI. The
user agent MAY use the Location field value for automatic
redirection. The server's response payload usually contains a short
hypertext note with a hyperlink to the new URI(s).


As you saw before the HTML body of Nginx does not mention the destination URL in the 301 redirect which should be something like <a href="https://forum.nginx">here</a> (see example of apache at the bottom)

This RFC follows another older RFC (deprecated):
The new permanent URI SHOULD be given by the Location field in the
response. Unless the request method was HEAD, the entity of the
response SHOULD contain a short hypertext note with a hyperlink to
the new URI(s).

I did an experiment and I found that Googlebot has a problem with the Nginx redirections because the Googlebot code expects the destination URL in the HTML body of the 301 redirect. On the other hand, I think that if the HTML body is empty, googlebot likes it and it relies on the location field for redirection.

There are two options, either to delete the whole HTML and rely on the location field only or add the destination URL in the HTML body.

I have noticed that and chose to delete the HTML body of their 301 redirect.
if you perform a "curl" or a "curl" it does not return anything. It means that the HTML body is empty for a 301 redirect from those websites.

FOr reference, the HTML body of Apache 301 redirect is like this:

<title>301 Moved Permanently</title>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://xx/">here</a>.</p>
<address>Apache Server at Port 80</address>
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 55
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready