remove www from the url

Igor Sysoev igor at sysoev.ru
Thu Feb 17 18:15:13 MSK 2011


On 17.02.2011, at 18:08, whiskybar wrote:

> Thank you all. Your solutions seem quite elegant.
>
> Just a note, I was hoping for something I can do inside the server  
> only
> declaration, just like I can do with the opposite redirection  
> mysite.com
> --> www.mysite.com:
>
> [code]
> server {
>    server_name www.mysite.com mysite.com;
>
>    if ($host !~* www\..*) {
>        rewrite ^(.*)$ http://www.$host$1 permanent;
>    }
> [/code]
>
> On the other hand, I feel your solution with the two server  
> declaration
> can even be a bit faster (not to mention easy to understand). Your
> solution suggests I should rewrite the above code into two server
> declarations as well.


Yes, two servers are easy to understand and faster, because
nginx does not run regex for main site:
http://nginx.org/en/docs/http/converting_rewrite_rules.html


--
Igor Sysoev
http://sysoev.ru/en/




More information about the nginx mailing list