I am trying to perform a simple URLRewriting. if you visit azamsharp.com it will take to some folder browsing structure it should go to http://www.azamsharp.com/AzamSharpWebApps/Default.aspx.
I don’t want to see the AzamSharpWebApps in the URL: Here is the URL Rewrite I am using:
<system.webServer>
<rewrite>
<rules>
<rule name="Virtual Director" enabled="true" stopProcessing="false">
<match url=".*" />
<conditions>
<add input="{MyDomains:{HTTP_HOST}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="{C:1}{REQUEST_URI}" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="MyDomains">
<add key="azamsharp.com" value="/AzamSharpWebApps/default.aspx" />
<add key="www.azamsharp.com" value="/AzamSharpWebApps/default.aspx" />
</rewriteMap>
</rewriteMaps>
</rewrite>
</system.webServer>
I don’t know how IIS UrlRewrite works, but at a general regex level you want to replace
^(?!/AzamSharpWebApps).+with/AzamSharpWebApps/$0The
^is start of string, and the(?!..)is a negative lookahead, saying “make sure the following text is not “/AzamSharpWebApps”, and then the .+ matches any character until the end of the string.In the replace side, the
$0indicates the entire captured text – so basically the regex is saying “if it doesn’t already start with “/AzamSharpWebApps”, prefix it with that.(You’ll need to experiment with whether you need a / before the $0 or not.)
Anyhow, looks like IIS uses
{C:0}instead of$0, just to be different, so I guess it will look something like this inside the rule:But possibly it needs more than just that.