【问题标题】:IIS URL Rewrite except specific siteIIS URL 重写,特定站点除外
【发布时间】:2018-07-15 20:55:48
【问题描述】:

我有 3 个站点(具有不同的域)托管在一台服务器上,但它们都具有相同的源和 web.config。站点 1 和 2 将停止,它们应该重定向到站点 4,但站点 3 将像现在一样工作...... 我添加了一个 RewriteMap,其中描述了所有页面重定向和使用该映射的规则:

 <rewrite>
      <rewriteMaps>
        <rewriteMap name="My_RewriteMap" defaultValue="localhost/site4/Welcome.aspx">
          <add key="/" value="localhost/site4/Welcome.aspx" />
          <add key="/default.aspx" value="localhost/site4/Welcome.aspx" />
          <add key="localhost/site2" value="localhost/site4/SpecificPage.aspx" />
          <add key="/page3.aspx" value="localhost/site4/MyPage.aspx" />
          <add key="new-page.aspx" value="localhost/site4/TheNewPage.aspx" />
...
</rewriteMap>
          </rewriteMaps>
          <rules>
                <rule name="Redirect rule1 for My_RewriteMap" stopProcessing="true">
                    <match url=".*" negate="false" />
                    <conditions>
                        <add input="{My_RewriteMap:{REQUEST_URI}}" pattern="(.+)" />
                    </conditions>
                    <action type="Redirect" url="{C:1}" appendQueryString="false" />
                </rule>
          </rules>
        </rewrite>

此代码适用于地图中描述的页面和默认值(如果地图中不存在特定页面)。 但这会重定向站点 1、站点 2 和站点 3。我不想重定向到站点 3。 是否可以使用重写 URL 功能? 我试图用

编辑match
<match url="localhost/Site3" negate="true" />

<match url="(localhost/Site3).*" negate="true" />

但两者都不起作用。

谢谢!

【问题讨论】:

    标签: asp.net redirect iis url-rewriting url-rewrite-module


    【解决方案1】:

    我完成了条件的下一个变化:

    <conditions trackAllCaptures="true">
      <add input="{HTTP_HOST}" pattern="localhost/Site3" negate="true" />
      <add input="{My_RewriteMap:{REQUEST_URI}}" pattern="(.+)" />
    </conditions>
    

    对于第一个条件,我说忽略主机(在{HTTP_HOST} 变量中)包含站点域的所有请求:localhost/Site3。 然后,第二个条件适用于地图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-05
      • 2015-04-28
      • 2013-01-21
      • 1970-01-01
      • 2013-09-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多