使用子域重定向到www web配置规则

时间:2013-05-03 07:34:28

标签: c# asp.net web-config

如何根据此

在webconfig中实现重定向规则
  1. http://quietincomes.com/(如果www不在网址中)重定向到http://www.quietincomes.com/
  2. http://www.shayam.quietincomes.com/重定向到http://www.quietincomes.com/shayam
  3. http://shayam.quietincomes.com/(如果www不在网址中)重定向到http://www.quietincomes.com/shayam
  4. http://www.shyam.quietincomes.com .....这个shyam是动态创建的.. 它可以是www.harshit.quietincomes.com,www.ankush.quietincomes.com

1 个答案:

答案 0 :(得分:1)

这样的事情应该有效:

<rule name="Primary hostname redirect" stopProcessing="false">
    <match url=".*" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^quietincomes.com$" />
    </conditions>
    <action type="Redirect" url="http://www.quietincomes.com/{R:0}" redirectType="Permanent" />
</rule>

<rule name="www.shayam redirect" stopProcessing="false">
    <match url=".*" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^www.shayam.quietincomes.com$" />
    </conditions>
    <action type="Redirect" url="http://www.quietincomes.com/shayam/{R:0}" redirectType="Permanent" />
</rule>

<rule name="shayam redirect" stopProcessing="false">
    <match url=".*" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^shayam.quietincomes.com$" />
    </conditions>
    <action type="Redirect" url="http://www.quietincomes.com/shayam/{R:0}" redirectType="Permanent" />
</rule>

如果你想让子域部分是动态的,就像这样(没有测试过它!):

<rule name="Dynamic redirect" stopProcessing="false">
    <match url="^(.*)\.quietincomes\.com$" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^(.*)\.quietincomes\.com$" />
    </conditions>
    <action type="Redirect" url="http://www.quietincomes.com/{C:1}/{R:0}" redirectType="Permanent" />
</rule>

匹配规则指定在重定向网址({C:1})中使用的反向引用(。*)