To remove the HTML body of nginx 301 302 redirects
When Nginx returns a 301 or a 302 redirect, it also returns a small useless HTML body.
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>
You can see this body when you perform a "curl talk.plesk.com" for instance. However today, many major domains don't return a HTML body, it is the case of facebook.com, twitter.com, youtube.com and www.plesk.com .
Funny enough, when i do a "curl www.plesk.com" it returns no html body. It means that someone at plesk remove this html body. But in plesk onyx it will always return the default html body that I have mentionned before. However, talk.plesk.com still returns the nginx html body.
It helps to save a bit of bytes for those who have a lot of redirects.
From a SEO point of view, I had an issue related to the HTML body of 301 nginx redirect. Google saw it as a crawl anomaly and soft 404. It means that google thought that the HTML body returned by nginx was a real document (sic) and thought that my server was not properly configured.
So to achieve this, I already did it locally, in nginx additional directives for my http to https.
errorpage 301 302 @30x;
location @30x {
defaulttype ""; #will remove Content-Type completely
return 300; # 300
is a filler: client will get the original HTTP status code
}
if ($sslprotocol = "") {
rewrite ^ https://$servername$request_uri? permanent;
}
I guess it is possible to do it in server.conf.
Today, all bots and browsers rely on the HTTP header field "Location" only to find the destination URL of a 301 or a 302. This is what happens when a bot hits www.plesk.com which does not return a HTML BODY in a 301 redirect.
example:
jojo@DESKTOP-IRG1A6S:~$ curl http://www.plesk.com/ -I
HTTP/1.1 301 Moved Permanently
Date: Fri, 02 Oct 2020 07:26:35 GMT
Connection: keep-alive
Cache-Control: max-age=3600
Expires: Fri, 02 Oct 2020 08:26:35 GMT
Location: https://www.plesk.com/
cf-request-id: 0589cdb1650000085f85953200000001
X-Content-Type-Options: nosniff
Server: cloudflare
CF-RAY: 5dbcb22f0ac2085f-CDG
Thank you for your input. We will consider this functionality in upcoming releases if it is popular. Everyone, please continue voting for this feature if you consider it important.
—
IG