LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Nginx Rewrite rule for subdomains (https://www.linuxquestions.org/questions/linux-server-73/nginx-rewrite-rule-for-subdomains-4175577196/)

Nolph 04-11-2016 12:40 PM

Nginx Rewrite rule for subdomains
 
Hello,

I have a web application that has had a name change. Im trying to figure out how to create a rewrite rule that forwards the users to the new domain for their account.

Example.

customer1.cloud.company.com -> customer1.company.cloud

We have many customers with their own domains setup. Below is what i've tried as a rewrite rule that doesn't seem to work.

Code:

  server_name ~^(\w+)\.cloud.company\.com$;
  return 301 $scheme://$1.company.cloud$request_uri;

When i try to visit the site i get redirected to ".company.cloud" seems as though the sub domain is being stripped out.

Thanks!

bathory 04-14-2016 08:34 AM

Hi,

You may try this:
Code:

  server_name ~^(.+)cloud.company\.com$;
  return 301 $scheme://$1company.cloud$request_uri;



All times are GMT -5. The time now is 05:40 PM.