【问题标题】:Simple URL Rewrite on IISIIS 上的简单 URL 重写
【发布时间】:2012-04-15 04:59:11
【问题描述】:

我有 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}absence

这是完整的 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>

【问题讨论】:

    标签: iis url-rewriting


    【解决方案1】:

    我终于明白了。
    事实证明,{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>
    

    【讨论】:

      猜你喜欢
      • 2011-12-12
      • 1970-01-01
      • 1970-01-01
      • 2015-01-20
      • 2017-12-15
      • 2022-01-11
      • 1970-01-01
      • 2011-12-19
      • 2017-11-05
      相关资源
      最近更新 更多