0

如何根据这个在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)重定向到http://www.quietincomes.com/shayam

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

4

1 回答 1

2

像这样的东西应该工作:

<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}) 中使用的反向引用 (.*)

于 2013-05-03T16:11:56.037 回答