1

我有1 个IIS 服务器,我想用它来托管2 个不同的网站(都在端口 80 上)。
我一直在尝试许多不同的组合(包括重定向),并且每次都出现问题(重定向循环、404、根本不工作等......)

我认为我需要的规则是这样的:

 - match any URL 
 - condition 1: match {HTTP_HOST} to my site URL 
 - condition 2: discard if {REQUEST_URI} is present 
 - action: rewrite URL to /dir1/index.html  

(repeat for site 2)

这里的问题似乎是条件 2 永远不会为真(我应该用什么来匹配{REQUEST_URI}?

这是完整的 XML:

<rewrite>
    <rules>
        <rule name="RuleForSite1" stopProcessing="true">
            <match url="(.*)" ignoreCase="false" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="^www\.mysite1\.com$" /> 
                <add input="{REQUEST_URI}" pattern=".+" negate="true" /> 
            </conditions>
            <action type="Rewrite" url="dir1/index.html" />
        </rule>
        <rule name="RuleForSite2" stopProcessing="true">
            <match url="(.*)" ignoreCase="false" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="^www\.mysite2\.com$" /> 
                <add input="{REQUEST_URI}" pattern=".+" negate="true" /> 
            </conditions>
            <action type="Rewrite" url="dir2/index.html" />
        </rule>
    </rules>
</rewrite>
4

1 回答 1

3

我终于弄明白了。
事实证明,它{REQUEST_URI}实际上从来都不是空/的,而是在其中没有任何内容时包含。
我还发现重定向效果更好。

这是我的最终设置:

<rewrite>
    <rules>
        <rule name="RuleForSite1" stopProcessing="true">
            <match url="(.*)" ignoreCase="false" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="^www\.mysite1\.com$" /> 
                <add input="{REQUEST_URI}" pattern="^/$"" /> 
            </conditions>
            <action type="Redirect" url="dir1/index.html" />
        </rule>
        <rule name="RuleForSite2" stopProcessing="true">
            <match url="(.*)" ignoreCase="false" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="^www\.mysite2\.com$" /> 
                <add input="{REQUEST_URI}" pattern="^/$"" /> 
            </conditions>
            <action type="Redirect" url="dir2/index.html" />
        </rule>
    </rules>
</rewrite>
于 2012-04-15T05:58:43.350 回答