【问题标题】:Old rewrite rules, how to change domain旧的重写规则,如何更改域
【发布时间】:2013-08-21 00:42:57
【问题描述】:

我已经有一段时间不使用 UrlRewrite 插件中的 <rewrite> 规则了,这让我发疯...

我想要完成的是将用户重定向到:

http://portals.presentkorttorget.se/GetRelationPdf.ashx?relationId=904

发送给

http://www.presentkorttorget.se/GetRelationPdf.ashx?relationId=904

只有 portals 更改为 www,我试图避免在 .NET 中进行重定向,重新编译并发布整个网站。 p>

我试过的是:

<rewrite>
    <rule name="PDF redirect to parent shop" patternSyntax="ECMAScript" stopProcessing="true">
      <match url="portals\.(([a-z]+)\.([a-z]+))$/GetRelationPdf\.ashx\?$" />
      <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
      <action type="Redirect" url="http://www.{R:1}/GetRelationPdf.ashx?{R:2}" />
    </rule>
</rewrite>

以及我使用http://www.gskinner.com/RegExr/测试的正则表达式的一些变体

【问题讨论】:

    标签: asp.net url-rewriting webforms


    【解决方案1】:

    要根据需要重定向子域,您必须使用条件:

    <rule name="PDF redirect to parent shop" patternSyntax="ECMAScript" stopProcessing="true">
      <match url="^GetRelationPdf\.ashx$" />
      <conditions>
            <add input="{HTTP_HOST}" pattern="portals\.(([a-z]+)\.([a-z]+))$" />
        </conditions>
      <action type="Redirect" url="http://www.{C:1}/GetRelationPdf.ashx" />
    </rule>
    

    此规则将检查 HTTP_HOST 是否以 portals. 开头并包含 2 个组,这些组由至少一个字母的 . 分隔。
    它还将检查请求的路径是否为GetRelationPdf.ashx(不区分大小写)。

    在重定向中,后向引用使用{C:1},从条件中获取信息,并且在触发重定向时默认追加查询字符串。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-22
      • 2015-10-07
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 2017-03-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多