(I’ve browsed through a ton of links on stack and articles like this on Microsoft http://forums.iis.net/t/1161629.aspx/1 Anything regarding sub-domains on stack either doesn’t have an answer or the solution simply doesn’t work. Please keep this in mind before flagging as "duplicate". I did my homework before asking)
I’m not certain whether or nto this has anything to do with MVC4 or not but here is my rule:
<rewrite>
<rules>
<rule name="Apply Sub-Domain as Query String Argument" stopProcessing="false">
<match url="^(.+)$" />
<conditions trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(^local[a-z0-9]+)\.domain\.com(.*)$" />
</conditions>
<action type="Rewrite" url="https://local.domain.com{C:2}?cobrand={C:1}" logRewrittenUrl="false" />
</rule>
</rules>
</rewrite>
I expect this for a url of https://subdomain.domain.com to send this into MVC4 as https://local.domain.com?cobrand=subdomain but it isn’t firing.
In my MVC application I have a view defined as:
<div>
Cobrand = @HttpContext.Current.Request.QueryString["cobrand"]
</div>
<div>
Requested URL = @HttpContext.Current.Request.Url
</div>
<div>
Path = @HttpContext.Current.Request.Path
</div>
With the following output for this requested url https://localdemo1.domain.com :
<div>
Cobrand =
</div>
<div>
Requested URL = https://localdemo1.domain.com
</div>
<div>
Path = /
</div>
My desired output is:
<div>
Cobrand = localdemo1
</div>
<div>
Requested URL = https://local.domain.com?cobrand=localdemo1
</div>
<div>
Path = /
</div>
A note about the site setup:
The IIS Site has bindings for:
HTTP::
local.domain.com
localdemo1.domain.com
localdemo2.domain.com
HTTPS::443 (No host configuration, can’t configure host on 443 but it’s configured to allow SSL)
PS: I tried this without HTTPS and it yields the same results, as not firing at all.
Here is what works for me:
Note that the
match urlas changed (accepting empty values) and thattype="Redirect"has replacedtype="Rewrite".{C:2}doesn’t work in this case (I am not able to tell you why…) but you can use{R:0}instead.