How to redirect to a different domain using NGINX?

前端 未结 8 875
旧时难觅i
旧时难觅i 2020-12-02 07:10

How can I redirect mydomain.com and any subdomain *.mydomain.com to www.adifferentdomain.com using NGINX?

8条回答
  •  爱一瞬间的悲伤
    2020-12-02 08:13

    server_name supports suffix matches using .mydomain.com syntax:

    server {
      server_name .mydomain.com;
      rewrite ^ http://www.adifferentdomain.com$request_uri? permanent;
    }
    

    or on any version 0.9.1 or higher:

    server {
      server_name .mydomain.com;
      return 301 http://www.adifferentdomain.com$request_uri;
    }
    

提交回复
热议问题