After Jeffreys comment, I changed my code to use setHeader to set a location but it did not change the behavior. So I looked into the actual http requests and headers using Google Chrome dev tools. I saw that the actual header location for the request was never changed no matter what code I used. It became clear to me that I was somehow not able to change header locations at all.
After realizing this, all it took was a quick Google search for: iis cannot change header location
This pointed me to this post: https://stackoverflow.com/questions/23508938/url-rewrite-keeps-original-host-location-when-reverse-proxy-301-redirects
Somehow the proxy in the IIS ARR was set to "Reverse rewrite host in response headers"! Unchecking this option solved the issue.
I am not sure if this is checked by default in ARR or if I mistakenly clicked it when setting up the server. I will make sure to check for that when I am setting up the production server. In case this is checked by default, I will request a change on the installation documentation.
Hi Tim, I'm not an expert on this material but I found the following articles on StackOverflow: SetHeader and RedirectView, and perhaps you can give it a try?