Frank Martin
Frank Martin

Reputation: 3451

URL rewrite not working in IIS due to regular expression issue

Trying to do URL rewriting in IIS. I have the following URL:

https://subdomain.maindomain.com/anyfolder/anyfile?param1=1&param2=2

I want to match the first part of URL i.e. https://subdomain.maindomain.com while it could be any string after that like I gave example above. But it is not working.

I am using following RegEx:

^http(s)?://subdomain.maindomain.com(.*)

What am I doing wrong?

EDIT

It only works if I define this RegEx (.*) which I don't want as I don't want to use wild card. I want to match specific URL.

Upvotes: -1

Views: 34

Answers (1)

Frank Martin
Frank Martin

Reputation: 3451

I asked ChatGPT and it gave me correct answer. Here is the code that you need to use:

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="ReverseProxyToBackend" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^subdomain\.maindomain\.com$" />
          </conditions>
          <action type="Rewrite" url="http://10.0.11.45:15155/{R:1}" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

Upvotes: 0

Related Questions