![](/img/trans.png)
[英]Multiple domains pointing to one server. Using a rewrite rule to set preferred domain
[英]Rewrite rule for sub domains is not firing
(我在Microsoft http://forums.iis.net/t/1161629.aspx/1上瀏覽了很多堆棧鏈接和類似文章,有關堆棧子域的任何內容都沒有答案或解決方案根本行不通。在標記為“重復”之前,請記住這一點。在進行詢問之前,我做了作業)
我不確定這是否與MVC4有關,但這是我的規則:
<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>
我希望將其作為https://local.domain.com?cobrand=subdomain
的網址以https://subdomain.domain.com
形式發送到MVC4,但不會觸發。
在我的MVC應用程序中,我的視圖定義為:
<div>
Cobrand = @HttpContext.Current.Request.QueryString["cobrand"]
</div>
<div>
Requested URL = @HttpContext.Current.Request.Url
</div>
<div>
Path = @HttpContext.Current.Request.Path
</div>
使用此請求的URL https://localdemo1.domain.com的以下輸出:
<div>
Cobrand =
</div>
<div>
Requested URL = https://localdemo1.domain.com
</div>
<div>
Path = /
</div>
我想要的輸出是:
<div>
Cobrand = localdemo1
</div>
<div>
Requested URL = https://local.domain.com?cobrand=localdemo1
</div>
<div>
Path = /
</div>
有關網站設置的注意事項:
IIS站點具有以下綁定:
HTTP ::
local.domain.com
localdemo1.domain.com
localdemo2.domain.com
HTTPS :: 443(無主機配置,無法在443上配置主機,但已配置為允許SSL)
PS:我在沒有HTTPS的情況下嘗試了此操作,結果是完全不觸發,結果相同。
這對我有用:
<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="Redirect" url="https://local.domain.com{R:0}?cobrand={C:1}" />
</rule>
</rules>
</rewrite>
請注意, match url
已更改(接受空值),並且type="Redirect"
替換了type="Rewrite"
。
{C:2}
在這種情況下不起作用(我無法告訴您原因...),但是您可以改用{R:0}
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.