Remove and add www

Asked byzina

Is it possible in nginx to add www. at first, and for the third-level domain to clean? For example:
domain.ru - & gt; www.domain.ru
 www.some.domain.ru - & gt; some.domain.ru

I want to note that the domain name is unknown in advance.
I would like to see an example of the config

Answers

kyle
server {
 server_name ~ ^ (? \ w \. \ w) $;

rewrite ^ / (. *) $ 9,876,90543 $ domain / $ 1 permanent;
}

server {
 server_name ~ ^ www \. (? \ w \. \ w \. \ w) $;

rewrite ^ / (. *) $ http: // $ domain / $ 1 permanent;
}

Somehow, I didn’t paint regexps for compliance with rfc :)
Replies:
hell, the parser ate everything:

server_name ~ ^ (? & ls; domain & gt; \ w \. \ w) $; - hharyati
server_name ~ ^ (? & Lt; domain & gt; \ w \. \ W) $;

rewrite ^ / (. *) $ http: // www. $ domain / $ 1 permanent; # (remove space between // and www)
server_name ~ ^ www \. (? & lt; domain & gt; \ w \. \ w \. \ w) $; - mahmoud
thanks, I will try - murilo cappucci
eli brooke
Explain why this is?
Replies:
The question was different, but if it is interesting, in order to have a standard domain mapping scheme + authorization did not fly as a bonus. - ebonne
Sorry for my illiteracy, but what is the "standard domain mapping scheme"? Is this also somehow regulated? RFC, can it?
For me, so "www" - a rudiment of the ancient Internet, from which all can not get rid of.
And so that authorization on cookies doesn't fly, set the path and domain parameters.

 
Set-Cookie: param=val; path=/; domain=.example.ru
- tom cork
That's just because of this rudiment and have to do so. At the expense of cookies in the course, but the fact is that you need to do so that authorization on subdomain1.domain.ru was different from subdomain2.domain.ru, at the same time the same for www.subdomain1.domain.ru and subdomain1.domain.ru. - liz matz
Set-Cookie: param=val; path=/; domain=.subdomain1.example.ru;
Set-Cookie: param=val; path=/; domain=.subdomain2.example.ru;

The second cookie for both subdomain2.example.com and www.subdomain2.example.ru, but not for * .subdomain1.example.com. - fityanisy
hm, did not know what is possible for domains of the 3rd level and higher. But the problem still remains, due to the fact that the framework is in charge of cookies, but I don’t want to hack it yet. The plus is that the view is standard from the point of view of all domains in the system. It is clear that there are no rfc on account of this. - brandy
Maybe there hacking nothing? If the framework can set the expiration date of cookies (par-p expire), then with high probability you can limit them to a specific domain and / or path. Unless it is a self-written framework where the work with the cookies was not taken care of a lot ... - silvialeggiamo
& gt; For me, “www” is a rudiment of the ancient Internet that everything cannot get rid of.

 w3.org does not think so :) But in general, in my opinion, it is normal to ignore the presence or absence of www, redirect to the option that seems right for you - no. I also liked the following feature on one site: when typing without www, a page appears where it is nice (but without graphics) that a greeting and a “menu” of choice for different services are displayed: www., Pda. etc. up to xml.rest. and json.rest :) - samantha starsick
Well, w3c are still conservatives :)
On virtually any host I have visited in everyday life, the default service is www. Often, www is the only thing provided there, so example.com and www.example.com are no different. And in such cases, I am for the www to not be.
Probably, many marketers suffered when there was a TV advertisement with the recitation “And visit our website on the Internet at the double double point,% dot% name% dot ru.” And some more “h ti pi colon slash slash” before this added :) - marisa simon
amy boese
ModeRewrite should help :) Unfortunately, I don’t know how he isn’t called Ngnix there ...
Replies:
ngx_http_rewrite_module it is called and above I used its rewrite directive :) - sam frazier
[maven] use absent in the repositories of the library :: Where in Ukraine to buy a Dual Mini ITX case? :: Svсhost.exe (netsvcs) in peak consumes up to 70% of the CPU power. Is it normal? :: Can I use the free basic package from Google for a small company? :: Need practical advice on test automation
Leave Repply forRemove and add www
Useful Links