简体   繁体   English

Nginx重写-仅重定向到一个域

[英]Nginx rewrite - only redirect to one domain

I am looking to redirect all requests that match http://s.domain.com to redirect to http://domain-new.com 我希望将所有与http://s.domain.com匹配的请求重定向到http://domain-new.com

I have the following and it seems to redirect all requests to the second domain. 我有以下内容,而且似乎将所有请求重定向到第二个域。 I would only like to redirect on an exact match. 我只想完全匹配进行重定向。

 if ($request_uri ~ "s.domain.com"){
       rewrite ^ http://domain-new.com;
     }

You can create a server block for the subdomain and redirect that to the new domain 您可以为子域创建一个服务器块,然后将其重定向到新域

server {
    listen 80;
    server_name s.domain.com;
    rewrite ^ http://domain-new.com$request_uri? permanent;
}

This should work for only redirecting the index: 这仅适用于重定向索引:

server {
    listen 80;
    server_name s.domain.com;
    # for index.xyz pages
    location ~ ^/index\..+$ {
        rewrite ^ http://domain-new.com$request_uri? permanent;
    }
    # for pages with index left out
    location / {
        rewrite ^/$ http://domain-new.com permanent;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM