IIS7 Url Rewrite添加www前缀但不在IP中

问题描述:

我在这里得到了一个非常有趣的情况,希望你能帮助我解决这个问题。IIS7 Url Rewrite添加www前缀但不在IP中

如果用户输入domain.com,我把它重定向到与此代码在我的web.config的帮助下www.domain.com:

<rules> 
    <rule name="Add WWW prefix" > 
     <match url="(.*)" ignoreCase="true" /> 
     <conditions> 
     <add input="{HTTP_HOST}" negate="true" pattern="^www\.(.+)$" /> 
     </conditions> 
     <action type="Redirect" url="http://www.{HTTP_HOST}/{R:1}" 
      appendQueryString="true" redirectType="Permanent" /> 
    </rule> 

这是简单,干净,就像一个魅力。但是,domain.com也有一个专用IP,比如19.12.121.121。当我尝试将我的站点与IP连接时,web.config将我重定向到:www.19.12.121.121。

所以问题是,我该如何防止这种情况?它将重定向域,但IP?

谢谢。

+0

Dup:http://*.com/questions/3090377/iis-url-canonical-rewrite-but-preserve-ip-address-access – jchapa

因为我可以看到你正在使用URL重写已经:

这是我用的规则,它为我的作品,包括IP地址。

<rule name="Redirect to WWW" patternSyntax="Wildcard" stopProcessing="true"> 
<match url="*" /> 
<conditions logicalGrouping="MatchAll"> 
    <add input="{HTTP_HOST}" negate="true" pattern="www.(YOUR DESIRED URL).com" /> 
</conditions> 
<action type="Redirect" url="http://www.(YOUR DESIRED URL).com/{R:1}" redirectType="Permanent" /> 
</rule>