B
B
Biggo2010-09-24 09:17:22
Nginx
Biggo, 2010-09-24 09:17:22

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

3 answer(s)
V
Vladimir Chernyshev, 2010-09-24
@VolCh

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 :)

M
MakeInstall, 2010-09-24
@MakeInstall

Explain why this is?

M
MakeInstall, 2010-09-24
@MakeInstall

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 question

Ask a Question

731 491 924 answers to any question