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

本文关键字:规则 配置 www web 重定向 | 更新日期: 2023-09-27 18:12:08

如何在webconfig中实现重定向规则

  1. http://quietincomes.com/(如果www不在url中)重定向到http://www.quietincomes.com/
  2. http://www.shayam.quietincomes.com/重定向到http://www.quietincomes.com/shayam
  3. http://shayam.quietincomes.com/(如果www不在url中)重定向到http://www.quietincomes.com/shayam
在http://www.shyam.quietincomes.com..

。这个shyam是动态创建的。可以是www.harshit.quietincomes.com, www.ankush.quietincomes.com

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

应该这样做:

<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>

匹配规则指定了在重定向url ({C:1})中使用的反向引用(.*)