0

I noticed that when I create a 301 redirection using nginx (rewrite, return 301), I get the following HTML body:

<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>

I would like to get rid of the HTML body of this 301 redirect generated by Nginx. Facebook and twitter got rid of those HTML bodies of their 301 redirect long time ago. It is a way to save some unsolicited bytes during 301 redirects.

So, I guess it is possible to create the HTTP header fields of the 301 redirect manually without calling rewrite or return 301. If I call "rewrite" or "return 301" in a location block of nginx, it will also generate the HTML body that I don't want. I can't modify the configuration files because I use Plesk. The Nginx configuration files are automatically generated.

So, I guess it is possible to manually create the following HTTP header fields with NGINX in a location block:

HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Tue, 15 Sep 2020 17:48:13 GMT
Content-Type: text/html
Content-Length: 162
Connection: keep-alive
Location: https://bloup.com/

How would you do it?

0

1 Answer 1

0

In Plesk, I understood that I had to encapsulate the redirection in a location / block.

So, when I typed on its own:

if ($scheme = http) {
        return 301 https://$server_name$request_uri;
    }

I got

<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>

Then, if I typed:

location / {
    if ($scheme = http) {
        return 301 https://$server_name$request_uri;
    }
}

I got rid of the HTML body response which is returned during a 301 redirect via Nginx.

Not the answer you're looking for? Browse other questions tagged .