Asp.net mvc 如果没有子域,则重写Web.config www

Asp.net mvc 如果没有子域,则重写Web.config www,asp.net-mvc,web-config,Asp.net Mvc,Web Config,有人知道如何修改下面的重写规则,仅在不存在子域的情况下添加前面的www吗 <rule name="WWW Rewrite" enabled="true"> <match url="(.*)" /> <conditions> <add input="{HTTP_HOST}" negate="true" pattern="^www\.([.a-zA-Z0-9]+)$" /> </conditions>

有人知道如何修改下面的重写规则,仅在不存在子域的情况下添加前面的www吗

<rule name="WWW Rewrite" enabled="true">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTP_HOST}" negate="true" pattern="^www\.([.a-zA-Z0-9]+)$" />
    </conditions>
    <action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>


TIA

我刚刚写了这个,并在我们的IIS 7.5机器上进行了测试。如果没有子域,它只添加“www.”

<rule name="Redirect naked domains (that do NOT have a custom sub-domain) to www.domain.com" enabled="true" stopProcessing="true">
    <match url="(.*)" />
        <conditions logicalGrouping="MatchAll">
            <add input="{HTTP_HOST}" negate="true" pattern="^www\." />
            <add input="{HTTP_HOST}" pattern=".*\..*\.com" negate="true" />
        </conditions>
    <action type="Redirect" url="http://www.{HTTP_HOST}{REQUEST_URI}" appendQueryString="true" redirectType="Permanent" />
</rule>