Remove and add www


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
8 views
Is it possible in nginx, when you request to any accepted second level domain to add www. first, and for third-level domain name removed? For example:
domain.ru -> www.domain.ru
www.some.domain.ru -> some.domain.ru

I want to note beforehand that the domain name is unknown.
I would like to see an example config
by | 8 views

3 Answers

0 like 0 dislike
server {
server_name ~^(?\\w\\.\\w)$;
\r
rewrite ^/(.*)$ www.$domain/$1 permanent;
}
\r
server {
server_name ~^www\\.(?\\w\\.\\w\\.\\w)$;
\r
rewrite ^/(.*)$ http://$domain/$1 permanent;
}
\r
Somehow, regexps for compliance with rfc to paint did not :)
by
0 like 0 dislike
Explain why this is?
by
0 like 0 dislike
ModeRewrite should help :) unfortunately I do not know as it was not properly called Ngnix...
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
27,373 users