1

I need help with a strategy on how to think regarding IIS - URL rewrite - Application Request Routing.

Example

Let's say that I can access my web server from outside my wifi via http://2X0.2X1.2X2.2X3 (this is how it works today). My IIS webserver respond to a request with a web page (port 80). Fine, I understand how it works.

In a close future, I also need to to deal with external systems posting data to my node-red server instance. The node-red server instance resides on the same Windows 10 computer but it answers on another port (1880)

This is what I want to achieve:

If I make an external request to http://2X0.2X1.2X2.2X3/myHomePage/2/34/56, something (IIS?) should translate it to (inside my wifi) http://127.0.0.1:80/Index.aspx?value1=2&value2=34&value3=56

http://2X0.2X1.2X2.2X3/api/switch/turnOn/20, should translate to http://127.0.0.1:1880/switch/turnOn/20

http://2X0.2X1.2X2.2X3/api/switch/turnOff/20, should translate to http://127.0.0.1:1880/switch/turnOff/20

My question: I am pretty sure that IIS URL rewrite / Application Request Routing can help me here but I am not sure how to achieve it. How should the rules look like? Should I use URL rewrite?

Edit 1:

Im trying to depict my situation here: enter image description here

Hauns TM
  • 117
  • 2
  • 2
  • 9

1 Answers1

1

You can use IIS inbound rewrite rule. It will be something like this:

For myHomePage:

enter image description here

For api:

enter image description here

May be I lost the point somewhere, but I think logic is right.

p.s. Edited my answer.

warder
  • 138
  • 1
  • 11
  • Little mistake, {REQUEST_URI} shoud be will slash: /(.*) – warder Aug 03 '18 at 04:22
  • Just one more thing. How do I deal with the situation http://2X0.2X1.2X2.2X3/myHomePage vs http://2X0.2X1.2X2.2X3/api? They need to be redirected to different ports inside my wifi. – Hauns TM Aug 03 '18 at 05:20
  • I updated my question with an image @warder. – Hauns TM Aug 03 '18 at 07:31
  • I've been trying to follow along with this, but for whatever reason the redirect to port 1880 just wont work, and IIS keeps wantign to send all requests through to port 80. Even tried usign a server variable for port, tried swapping the regex in to the pattern field, and even tried highly limiting the request to the "my HomePage" example with regex. Always with the redirect to port 80. Super frustrating. – anakaine May 05 '21 at 04:42
  • 1
    I've noticed that in the `Conditions` list, the server variable should probably not be `QUERY_STRING` but `PATH_INFO`. [Here are the most important ones.](https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#accessing-url-parts-from-a-rewrite-rule). – Oliver Aug 09 '21 at 21:14