Nginx server redirect

hi
if any one goes to
XXX.aaa.com/bbb

i want to do a permanent redirect to
aaa.com/bbb

any suggestions on how to do this?
thank you

On Sat, Jun 20, 2009 at 12:44 PM, Kevin
Castiglione[email protected] wrote:

server {
listen 80;
server_name .aaa.com;
rewrite ^.
http://aaa.com$uri;
}

On Fri, Jun 19, 2009 at 11:17 PM, Edho P Arief [email protected]
wrote:

any suggestions on how to do this?
thank you

server {
listen 80;
server_name .aaa.com;
rewrite ^.
http://aaa.com$uri;
}

edho:
thanks for this. im going to be handling multiple domains, so is it
possible
to do this rewrite without hardcoding?

rewrite ^.* http://aaa.com$uri;

for ex somthing like
rewrite ^.* http://$maindomain$uri;

On Sat, Jun 20, 2009 at 2:15 PM, Kevin Castiglione <
[email protected]> wrote:

edho:
thanks for this. im going to be handling multiple domains, so is it
possible to do this rewrite without hardcoding?

rewrite ^.* http://aaa.com$uri;

for ex somthing like
rewrite ^.* http://$maindomain$uri;

also this rewrite rule gives Redirect Loop error on all browsers.
thank you

On Sun, Jun 21, 2009 at 12:04 PM, Edho P Arief[email protected]
wrote:

hi

 rewrite ^.* http://aaa.com$uri;
did you mean:
NNN.somedomain.tld => somedomain.tld
for any somedomain.tld?

here it is
server {
listen 80;
server_name ~(.).([^.]).([^.])$;
set $domain $2.$3;
rewrite ^.
http://$domain$request_uri permanent;
}

On Sun, Jun 21, 2009 at 4:17 AM, Kevin
Castiglione[email protected] wrote:

XXX.aaa.com/bbb
 listen 80;
for ex somthing like
 rewrite ^.* http://$maindomain$uri;

also this rewrite rule gives Redirect Loop error on all browsers.
thank you

I forgot to escape the dot.

did you mean:
NNN.somedomain.tld => somedomain.tld
for any somedomain.tld?

On Sun, Jun 21, 2009 at 12:19 PM, Edho P Arief[email protected]
wrote:

here it is
    server {
        listen 80;
        server_name ~(.).([^.]).([^.])$;
        set $domain $2.$3;
        rewrite ^.
http://$domain$request_uri permanent;
    }

make sure that you have the server_name set on nginx or it’ll redirect
to .

this will catch all anydomain.tld
server {
listen 80;
server_name ~[^.].[^.];
return 403;
}

On Sat, Jun 20, 2009 at 10:30 PM, Edho P Arief [email protected]
wrote:

make sure that you have the server_name set on nginx or it’ll redirect to .
can you tell how i set server_name on nginx for this to work?

this will catch all anydomain.tld
server {
listen 80;
server_name ~[^.].[^.];
return 403;
}

i dont understand what you mean by catch all anydomain.tld?
can you pl. explain this?
thanks a lot!

On Sat, Jun 20, 2009 at 10:04 PM, Edho P Arief [email protected]
wrote:

hi

rewrite ^.* http://aaa.com$uri;
did you mean:
NNN.somedomain.tld => somedomain.tld
for any somedomain.tld?

this is exactly what i want
NNN.somedomain.tld => somedomain.tld

On Sun, Jun 21, 2009 at 7:32 AM, Edho P Arief [email protected]
wrote:

           listen 80;

without this block, the redirection will go like this:
NNN.abcd.com => abcd.com => . (dot)

with this it’ll access correct site instead (stop at abcd.com)

is it possible to do this with just one server block for multiple
domains:
for ex:
server {
listen 80;
server_name .abcd.com .efgh.com .ijkl.com

}

Kevin Castiglione Wrote:

also this rewrite rule gives Redirect Loop error
on all browsers.
thank you

You need something like

server {
server_name XXX.aaa.com/bbb;
listen 80;

rewrite ^ AAA | American Automobile Association? permanent;
}

Posted at Nginx Forum:

On Sun, Jun 21, 2009 at 8:21 PM, Kevin
Castiglione[email protected] wrote:

    }

make sure that you have the server_name set on nginx or it’ll redirect to
.

can you tell how i set server_name on nginx for this to work?

create separate server block for each domain name

server {
listen 80;
server_name abcd.com;

}

which will be used when nginx detects the domain as abcd.com

without this block, the redirection will go like this:
NNN.abcd.com => abcd.com => . (dot)

with this it’ll access correct site instead (stop at abcd.com)

can you pl. explain this?
thanks a lot!

catch whatever that matches such pattern (asd.com, fghqwe.net,
zxclkj.org, asdf.ghjk, etc) and return 403 (in this example)

without this block, the previous server_name
(~(.).([^.]).([^.]*)$;) will catch this pattern and redirect to
‘.’