0
votes

Summary

My Express server returned a redirect URL response, such as redirect to
https://domain_A.com/babababa

I used IIS URL Rewrite to redirect URL request to my Express server. Requests through IIS to Express Server, the returned redirect URL has been modified, domain changed to my domain, such as
changed from https://domain_A.com/babababa to https://my-Domain.com/babababa

Question Details

my Express Server

My Express server started on http://localhost:8022, If I go to the route http://localhost:8022/login, it will redirect me to a page outside my network https://domain_A.com/babababa

my IIS and URL rewrite setup

I have setup my IIS to connect to my Express server using URL Rewrite.

  • My IIS in my domain: https://my-Domain.com
  • URL rewrite setup: https://my-Domain.com/Express will forward the request to http://localhost:8022
  • as a result, if I go to https://my-Domain.com/Express/login, the request forwarded to Express server, which is same as going to http://localhost:8022/login

Testing

If I go to my express server directly by URL http://localhost:8022/login, I can see my page redirect to https://domain_A.com/babababa?... correctly. In developer console > Response Headers > Location it shows https://domain_A.com/babababa?...

If I go through the IIS by URL https://my-Domain.com/login, in result I have been redirect to a wrong URL https://my-Domain.com/babababa?... (this page not exists)
In developer console > Response Headers > Location it shows https://my-Domain.com/babababa?...
I believe the response location's domain is replaced by my domain.

root cause and fixing?

Any ideas why my IIS response redirect URL's domain being modified? any information and suggestion of how to fix are appreciated! Thanks for any help!

2
Hi, has the problem been solved? If you think my reply is helpful to you, you can mark it as an answer. - Ding Peng
thank you for your reply, actually I have a different issue which related to Response redirect to a 3rd party page. I currently "Reserve rewrite host in response header" to avoid my issue, but that still created another issue when I redirect to myself the IIS returned "localhost". That is much complicated but I found some other post here may help. Thanks for your answer again. - Eric Cheng
I think my question is not very clear about my issue, anyway I found some other resource that described the same issue more details and with some direction how to resolve. More related question: serverfault.com/questions/849064/… - Eric Cheng
Is the problem solved now? - Ding Peng
thank you @DingPeng for your answer, unfortunately, your answer did not resolve my problem. I may need some solution like Outbound rule set up to resolve the issue. Thanks anyway. - Eric Cheng

2 Answers

0
votes

Based on your description I think you might want to use IIS as a reverse proxy, here is a demo:

First click Application Request routing cache(If ARR is not installed, you have to install it first.):

enter image description here

Set up reverse proxy:

enter image description here

Enable reverse proxy:

enter image description here

This is my URL Rewrite:

        <rewrite>
            <rules>
                <rule name="Test" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="http://vpedin456VM/test.html" />
                </rule>
            </rules>
        </rewrite>

This rule will forward all localhost requests to vpedin456VM.

enter image description here

Access localhost and you will see test.html in vpedin456VM, IIS will distribute the requests on localhost to vpedin456VM.

0
votes

Glad to came across this link.

Had the same problem with my project.

HTTPS -> to HTTP using URL rewrite is working. Had a problem with express redirection, the redirection to a public URL was being rewriting back to the in-house web server.

In IIS ARR, unchecking the "Reverse rewrite host in response headers" solved the problem.

(Sorry can't vote due to low reputation. I will come back to this page once I earned at least 15 in reputation)

Thank you guys