title: Redirecting from web app behind Azure application gateway
body: <p>I have two web apps setup in Azure, and for simplicity let's call them webapp1 and webapp2. They sit behind an application gateway, which is selecting the correct web app based on the subdirectory in the URL. </p>
  
  <p>Here's a basic example of how I've set it up:</p>
  
  <p>www.mydomain.com -> webapp1 (the default route)</p>
  
  <p>www.mydomain.com/app -> webapp2</p>
  
  <p>This is working fine, except for one problem: if webapp2 redirects to the login page, for example, the domain in the URL changes to the azurewebsites.net domain. Instead of redirecting to www.mydomain.com/login, it's going to webapp2.azurewebsites.net/login.</p>
  
  <p>I'm fairly new to Azure application gateway, but I know it injects the x-forwarded-* and x-original-host headers. I assumed the gateway would either alter the redirected url request to correct the domain or the config on the web app would use the x-original-host instead. Neither of these things are happening. </p>
  
  <p>Is there a way to configure either the web app or the gateway to make sure the host name doesn't change on redirects? Would this scenario work better with a separate web app/VM with a classic IIS reverse proxy setup instead of the application gateway?</p>