Answer the question
In order to leave comments, you need to log in
Remove and add www
Is it possible in nginx to add www. in the beginning, and for the third-level domain to clean? For example:
domain.ru -> www.domain.ru
www.some.domain.ru -> some.domain.ru
I would like to draw your attention to the fact that the domain name is unknown in advance.
I would like to see an example config
Answer the question
In order to leave comments, you need to log in
server {
server_name ~^(?\w\.\w)$;
rewrite ^/(.*)$ www. $domain/$1permanent;
}
server {
server_name ~^www\.(?\w\.\w\.\w)$;
rewrite ^/(.*)$ http://$domain/$1 permanent;
}
Somehow, I didn't write regexps for rfc compliance :)
ModeRewrite should help :) Unfortunately, I don’t know how it’s not called Ngnix correctly…
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question