Answer the question
In order to leave comments, you need to log in
Redirect from www to non-www?
Greetings!
I broke my brain how to redirect to a domain “from www” to “without www”.
A-records are spelled (@ and www), the domain is delegated to Yandex
server {
listen 000.000.000.00:80;
server_name mydomain.ru www.mydomain.ru;
root /home/user/web/mydomain.ru/public_html;
index index.php index.html;
..................
server {
server_name "~^(www\.)?(.*)$" ;
return 301 http://$2$request_uri ;
}
server {
server_name www.mydomain.ru;
rewrite ^(.*) http://mydomain.ru$1 permanent;
}
server {
listen 000.000.000.00:80;
server_name mydomain.ru;
root /home/user/web/mydomain.ru/public_html;
index index.php index.html;
server {
server_name www.mydomain.ru;
return 301 $scheme://mydomain.ru$request_uri;
}
server {
listen 000.000.000.00:80;
server_name mydomain.ru;
root /home/user/web/mydomain.ru/public_html;
index index.php index.html;
server {
...
listen 000.000.000.00:80;
server_name mydomain.ru www.mydomain.ru;
return 301 $scheme://mydomain.ru$request_uri;
...
}
Answer the question
In order to leave comments, you need to log in
server {
server_name www.example.com;
return 301 $scheme://example.com$request_uri;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question