Nginx rewrite infinite loop

Hi.

I tried to rewrite all non-www url to www url, but when i tried to
access the site, i got the infinite loop. following is my config

server {
server_name www.example.com;

}
location / {

rewrite ^ http://example.com$request_uri? permanent;
proxy_pass http://example.com

}

but if i change to redirect to the www url with locale(like, en, zh_CN),
it works fine. following is the config.

server {
server_name www.example.com;
}

location / {

rewrite ^ http://example.com/zh_CN$request_uri? permanent;

}

location ^~ /zh_CN {

proxy_pass http://example.com
}

any help is appreciated.

Thank You

Steve

On Fri, Jul 29, 2011 at 11:33 AM, Steve Z. [email protected]
wrote:

rewrite ^ http://example.com$request_uri? permanent;
proxy_pass http://example.com

do you want to proxy or rewrite? R

Also why do people like posting snippet of their config file? This one
isn’t even a valid one with location block outside sever block.

hi

i would to have both rewrite and proxy. Rewrite is for redirecting
non-www url to www urls, proxy_pass is passing to my upstream block.

Thank You

Steve

On 29 Jul 2011 05h33 WEST, [email protected] wrote:

Hi.

I tried to rewrite all non-www url to www url, but when i tried to
access the site, i got the infinite loop. following is my config

server {
server_name www.example.com;

}
location / {

rewrite ^ http://example.com$request_uri? permanent;
proxy_pass http://example.com

}

any help is appreciated.

Thank You

Steve

server {
server_name www.example.com;

location / {
proxy_pass http://example.com;
}

}

server {
server_name *.example.com;

rewrite ^ http://www.example.com$request_uri? permanent;

}

— appa