How To Match Several non-www Host Headers Using IIS7 Rewrite Module
I need to redirect several host headers without www. to their www. counterpart. I can't seem to get it working quite right. This is what I've got so far:
<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" />
&开发者_开发技巧lt;/rule>
The domains are all totally different, so there is no common string to match except for .com.
My regex is probably not right...
Try this:
<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>
EDIT: fixed regex, should work now.
精彩评论