2011-02-28 39 views
0

我需要重定向多个主机头文件而不使用www。到他们的www。对口。我似乎无法完成正确的工作。这是我到目前为止有:如何使用IIS7重写模块匹配几个非www主机头文件

<rule name="Redirect to WWW" stopProcessing="true"> 
<match url=".*" /> 
    <conditions> 
    <add input="{HTTP_HOST}" pattern="^www\." negate="true" /> 
    </conditions> 
    <action type="Redirect" url="http://www.{C:0}/{R:0}" redirectType="Permanent" /> 
</rule> 

的域都完全不同,所以没有普遍的字符串匹配除了.COM。

我的正则表达式可能是不对的......

回答

4

试试这个:

<rule name="Redirect to WWW" stopProcessing="true"> 
    <match url="(.*)" /> 
    <conditions> 
     <add input="{HTTP_HOST}" negate="true" pattern="^www\..*" /> 
    </conditions> 
    <action type="Redirect" url="http://www.{HTTP_HOST}/{R:1}" redirectType="Permanent" /> 
</rule> 

编辑:固定的正则表达式,现在应该工作。

+0

谢谢Scott!这工作完美。当你需要将100个主机头重定向到www版本时,它确实节省了时间。 – Corgalore 2011-02-28 17:36:13

+0

你打赌,祝你好运:) – 2011-02-28 17:46:29