Answer the question
In order to leave comments, you need to log in
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
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;
}
}
location / {
return 301 https://www.site.ru;
}
"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 questionAsk a Question
731 491 924 answers to any question