IIS URL-rewrite doesn't work

7,052

Out of the box, UrlRewrite can only do rewrites to the same page, like this:

<rule name="Rewrite to article.aspx">
<match url="^article/([0-9]+)/([_0-9a-z-]+)" />
<action type="Rewrite" url="article.aspx?id={R:1}&amp;title={R:2}" />
</rule>

It seems you are trying to do a rewrite to entirely another site on another domain and possibly do ssl offloading - this is what Reverse Proxy does. For this to work, you have to have Application Request Routing installed.

What I would do to debug this config is:

  1. Replace rewrite action with a redirect and see if it works - this way you make sure that the rule gets applied for your request.
  2. If all you're trying to do is a rewrite within your site, change the rewrite url to a relative one.
  3. If you indeed need to do a rewrite to a different site, install and configure ARR (which itself can bring another set of problems)
Share:
7,052

Related videos on Youtube

Doron Zavelevsky
Author by

Doron Zavelevsky

Updated on September 18, 2022

Comments

  • Doron Zavelevsky
    Doron Zavelevsky over 1 year

    I have an IIS setup with redirect rules that work perfectly fine on my Windows machine. However - I'm starting to use Mac - so I installed a VirtualBox VM with windows on it and used the exact same setup. Now the windows VM I got running on VirtualBox for Mac is the same as the same as the physical Windows machine I used so far.

    Problem is that the url redirect is not working. From the guest machine (windows) I browse to the URL that should be redirected and it doesn't happen properly. I assume this has something to do with how I configure the network for the virtual machine - do I have to create port forwarding rules? Which ones?

    Here's the rule - from web.config (it works just fine on a physical machine):

    <rule name="API" patternSyntax="ECMAScript" stopProcessing="true">
        <match url="api/.*" />
        <action type="Rewrite" url="https://api.MyDomain.com/{R:0}" />
    </rule>
    

    Regarding the VM - I defined two network adapters:

    • 1: NAT

    • 2: Host-only Adapter

    Note that I have access to the web from the guest machine, I can also access my web service locally - all is fine except for the URL rewrite when the rule is applied.

  • Doron Zavelevsky
    Doron Zavelevsky about 9 years
    I accept your answer - and I was about to answer my own question. It turns out that I missed one setup step when moving from my old machine to the VM - to install and configure ARR (check enable proxy). Thanks!