5

I need to create a URL rewrite rule in IIS for the following:

From:

http://hostname/virtual_path_folder/myisapi.dll?a=1&b=1

To:

http://hostname/myisapi.dll?a=1&b=1

Basically, I'd just like to hide the virtual_path folder if possible.

cheesemacfly
  • 11,622
  • 11
  • 53
  • 72
Technomorph
  • 55
  • 1
  • 3

1 Answers1

9

You could go with the 2 following rules:

<rules>
    <rule name="Redirect if virtual_path_folder" stopProcessing="true">
        <match url="^virtual_path_folder/(.*)$" />
        <action type="Redirect" url="{R:1}" />
    </rule>
    <rule name="Rewrite to sub folder">
        <match url="^.*$" />
        <action type="Rewrite" url="virtual_path_folder/{R:0}" />
    </rule>
</rules>

The first one, Redirect if virtual_path_folder, will redirect every request starting with virtual_path_folder/. It will prevent anyone from accessing your content using the sub folder.

The second one rewrites any request (^.*$) to the sub folder: virtual_path_folder/{R:0}

cheesemacfly
  • 11,622
  • 11
  • 53
  • 72
  • @cheesemacfly I have a similar problem to fix. Your solution works great but what if I have a virtual_path_folder_B and virtual_path_folder_C for which the rule must not be applied? I tried to add ` ` but it doesn't do the trick! – MaxSC Jun 05 '13 at 15:54
  • @MaxS-Betclic You want to avoid the `Rewrite` if the requested url is `http://yourwebsite.com/virtual_path_folder_C` and show the content of `virtual_path_folder_C` instead? – cheesemacfly Jun 05 '13 at 16:28
  • @cheesemacfly Yes that's it! – MaxSC Jun 05 '13 at 17:09
  • @MaxS-Betclic To do this, you could change the second rule pattern (``) to something like: ``. It would prevent the rewrite when the url starts with `virtual_path_folder_C`. Would it work for you? – cheesemacfly Jun 06 '13 at 13:52
  • 1
    @cheesemacfly Thanks for your reply. Actually I wrote a new [question](http://stackoverflow.com/questions/16965413/iis-rewrite-module-and-sub-applications), it will be easier than adding stuff to comments! – MaxSC Jun 06 '13 at 14:57