0

I am trying to match a ? in my url rewrite section in my web config, I am using IIS Express so I can not add the rule via IIS manager.

 <rules>
        <rule name="LocationDetail" stopProcessing="true">
            <match url="^location-detail\?province=([A-Za-z]{2})$" />
            <action type="Redirect" url="LocationDetail"/>
        </rule>
    </rules>

As you can see I am already escaping the ?. Is there something I am missing?

I also modify the url so that the the question mark is not needed to see if the question mark is the reason it was not matching.

<rules>
        <rule name="LocationDetail" stopProcessing="true">
            <match url="^location-detailprovince=([A-Za-z]{2})$" />
            <action type="Redirect" url="LocationDetail"/>
        </rule>
    </rules>

It was. Once the question mark was removed it matched correctly and I was redirected correctly.

Jack Thor
  • 1,554
  • 4
  • 24
  • 53
  • That's impossible. When a URL is served by IIS to the rewrite rule engine, it is broken down to different components (host name, query string, file path and so on), and the question mark is gone. Thus, usually you shouldn't attempt to match the question mark itself in `match` tag, but should detect if a URL component (query string for example) exists or not. If you insist to match the original full URL, you might work on a certain server variables like `CACHE_URL` in a condition, https://learn.microsoft.com/en-us/iis/web-dev-reference/server-variables – Lex Li Oct 31 '22 at 22:44

0 Answers0