H
H
hdtor2019-08-11 06:24:52
Nginx
hdtor, 2019-08-11 06:24:52

How to disable redirect to https for robots.txt?

There is a site that works under nginx, the entire site redirects from http to https, but actually how to make robots.txt open in the same way via http?
If in .htaccess, it's done like this:

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/robots.txt$ [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]

How to do it on nginx?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
H
hdtor, 2019-08-11
@hdtor

Finally decided this:

server {
     listen 80;
     server_name site.ru;
   root  /var/www/site.ru;
   
  location ~* ^.+\.(txt|css|js|xml)$ { }

    location / {
        return 301 https://site.ru$request_uri;
    }
}

D
dodo512, 2019-08-11
@dodo512

server {
    listen 80;
    server_name site.ru www.site.ru;
    root /var/www;

    location = /robots.txt {   }
    
    location / {
        return https://site.ru$request_uri;
    }
}

V
Viktor Taran, 2019-08-11
@shambler81

And why do you think this is necessary?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question