F
F
foxse2017-01-13 19:01:34
Nginx
foxse, 2017-01-13 19:01:34

Nginx redirect from any site set to https://www.site.ru with codes 200, 301?

Hello
Does anyone know the configuration for nginx to redirect from any set of sites to https://www.site.ru with codes 200, 301 ?
For example, typing www.site.ru , site.ru , https://site.ru , www.site.ru , site.ru will go to https://www .
I tried different ones from Habr, stackoverflow.com , https://wiki.nginx.org , etc.
Sometimes it gives 307. The chain is 307 => 301 => 200 or 307 => 200.

Important for SEO? Perhaps I'm wrong.

Excellent result with codes and avito.ru redirect . Also on nginx.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xbox, 2017-01-19
@xbox

Code 200 is not a redirect.
The redirect is usually with the code 301, 302.
With a "permanent" redirect, first your page gives the code 301 and indicates a new address. And then a new page opens and, if everything is fine, it returns the code 200.
Here is an example of how to redirect http://site.ru/what_you want and http://www.site.ru/what_you want with code 301 to https:/ /www.site.ru/what_everything
For https://site.ru it is done in the same way. (The config is written in a separate "server" block.)

server {
    listen 100.100.100.100:80;					
    server_name site.ru www.site.ru;

    location / {		
      rewrite ^(.*)$ https://www.site.ru$1 permanent;
    }	
  }

If you do not need to save the path after the domain when redirecting, then you can use an even shorter construction
location / {
      return 301  https://www.site.ru;
      }

I don't understand why you need a 307 redirect. And even more so, I don’t understand why do a double redirect 307=>301=> and so on. It makes no sense, including SEO. And if someone did this, including a large resource, this does not mean that you need to copy it. Double redirect only increases page response time.
For SEO purposes, 301 redirects are used. Search engines work great with it and "glue" addresses.
Below is a description of the 307 redirect from Wikipedia. Is such a redirect really necessary for your example?
You write:
Actually the browser remembers not it. Some browsers remember 301 redirects. This means that if page "A" links to page "B" through a 301 redirect, then when you retype "A" in the browser, the browser immediately loads "B" without first hitting "A". The fact that in your example "A" and "B" have the same different address, which differs only in the http/https protocol, is just a special case. Browsers could just as well remember the redirect _http//site1.eu/page1 to _https//site2.biz/page2

F
foxse, 2017-01-20
@foxse

"With code 200, this is not a redirect." This is clear.
The problem was with the code 307. The chain is 307 => 301 => 200 or 307 => 200. In the FireFox browser, the code 307 is not observed.
It turns out to be related to the use of an SSL certificate and the header Strict-Transport-Security
server {
...
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
...
The browser remembers that https:// is being used, and in case of accessing the site via an insecure connection, it performs an internal transition with the 307 code to https://.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question