【问题标题】:Building IIS Redirect Rule to Redirect Product Page to New URL Passing Product ID构建 IIS 重定向规则以将产品页面重定向到新 URL 传递产品 ID
【发布时间】:2019-11-11 16:27:51
【问题描述】:

我正在尝试使用 IIS 7 中的 URL 规则引擎将我们当前的产品页面重定向到我们的新产品页面。

旧页面:

example.com/itemform.aspx?item=X12878
example.com/itemform.aspx?item=Y87304&showmenu=T

新网址

example.com/c/product/X12878
example.com/c/product/Y87304

尝试

<rule name="Product Page Redirect">
  <match url="/itemform\.aspx\?item=([.a-zA-Z0-9]+)$" />
  <action type="Redirect" url="https://newsite.com/x/product/{C:1}" redirectType="Permanent" />
</rule>

根据 Emma 的建议完成重写规则

<rewrite>
  <rules>           
    <rule name="Product Page Redirect" stopProcessing="true">
      <match url="/itemform\.aspx\?item=([A-Za-z0-9.]+)" />
      <conditions>
      </conditions>
      <action type="Redirect" url="https://newsite.com/x/product/{R:1}" appendQueryString="false" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

【问题讨论】:

    标签: regex redirect iis


    【解决方案1】:

    我的猜测是,删除结尾 $ 锚可能只会使匹配有效:

    <rule name="Product Page Redirect">
      <match url="/itemform\.aspx\?item=([A-Za-z0-9.]+)" />
      <action type="Redirect" url="https://newsite.com/x/product/{C:1}" redirectType="Permanent" />
    </rule>
    

    但是,也许不是。

    【讨论】:

    • 应用您的修复后,IIS 测试模式工具显示成功匹配这些模式,但页面仍不会重定向。啊。
    【解决方案2】:

    根据您的描述,如果您想使用 url rewrite 来获取正确的查询字符串。

    更多细节,您可以参考以下代码:

                <rule name="QueryStringRue" enabled="true" stopProcessing="true">
                    <match url="itemform.aspx" />
                    <conditions>
                        <add input="{QUERY_STRING}" pattern="^item=([0-9a-zA-Z]*)" />
                    </conditions>
                    <action type="Redirect" url="http://example.com/c/product/{C:1}" appendQueryString="false" />
                </rule>
    

    结果:

    【讨论】:

    • 这似乎更接近,它现在正在重定向我,但产品 ID 没有附加到重定向 URL。
    • 没关系...看起来这正在工作,但重定向的站点在页面加载时失败。感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-10
    • 2018-10-07
    • 1970-01-01
    • 2023-04-09
    相关资源
    最近更新 更多