views:

18

answers:

1

How can I write an nginx rewrite that will redirect traffic sent to the root of a site but not sent to paths below root?

In other words:

I want to rewrite any request to http://foo.bar.com to redirect to http://foobar.com

But any request for http://foo.bar.com/baz should go ahead and go there.

The below redirects any request to foo.bar.com because I'm matching on the host. I'm no rewrite master (especially on nginx), but I think I'd like to match on a concatenation of $server_name and $request_uri. I'm just not sure how to combine the two of them into one string to match against the way I can w/ Apache.

if ($host ~* ^foo\.bar\.com$){
  rewrite ^.*$ http://foobar.com permanent; 
}
+1  A: 

rewrite ^/$ http://foobar.com permanent;

Shai
Doh! Seems so simple once you see the right answer... Thanks!
trevrosen