Search code examples
iis-7iis-7.5azure-web-app-servicearr

Redirect rule to an IP


I have a site hosted in azure. I want to debug a certain scenario which happens there (in test env) and so I want all requests that come to that URL i.e. https://test.com to be redirected to my local IP ( after I port forward and handled everything on my own computer. I have added a rule which almost works and this is what it looks like:

<rule name="Reverse" stopProcessing="true">
            <match url=".*" />          
            <action type="Redirect" url="52.52.52.52/api/..." redirectType="Found"/>             
</rule>

What happens is that when the request comes to the server, it prepend the current host URL to the IP and it looks like this:

test.com/52.52.52.52

How do can I configure to not add the host name?


Solution

  • It's been a while since I worked with the rewrite rules so this answer might not be definitive. But the "Found" 'redirectType' is going to result in a 302 response to the client (browser) and will include a "Location:" header with a full URL. Since you have not provided the host in your URL, it will use the host name that was in the request.

    You need to put the protocol in the action "url=" like 'url="https://52.52.52.52/api/...'.

    If you need this to work for both HTTP and HTTPS, you can either parse our the protocol from the {REQUEST_URI} or create a rewrite map and use the {HTTPS} server variable. Details are here.