开发者

Nginx re-writes combining $server_name and $request_uri?

开发者 https://www.devze.com 2023-01-04 21:59 出处:网络
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?

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 t开发者_Python百科hink 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; 
}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消