【问题标题】:IIS Rewrite for single query string to SEO version将单个查询字符串的 IIS 重写为 SEO 版本
【发布时间】:2019-11-08 09:19:40
【问题描述】:

我尝试了几个小时来让以下 IIS 重写工作:

传入网址:

https://example.com/services/control/status?Id=SO1234567

预期输出:

https://example.com/orders/detail/SO1234567

IIS 重写规则:

<rule name="Custom rewrite rule" patternSyntax="ExactMatch" stopProcessing="true">
    <match url="^services/control/status\?Id=(SO|so){1}([0-9]*)" />
    <action type="Rewrite" url="/orders/detail/{R:0}" appendQueryString="false" logRewrittenUrl="true" />
</rule>

其他信息:

  • 我在 IIS 中运行一个网站。
  • 此网站下的 API 的 1 个 Web 应用程序。
  • 网站中的 Angular 文件。

角度规则:

<rule name="Angular Routes" stopProcessing="false">
    <match url=".*" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
    </conditions>
    <action type="Rewrite" url="/" />
</rule>

完成重写部分:

<rewrite>
    <rules>
        <clear />
        <rule name="Angular Routes" stopProcessing="false">
            <match url=".*" />
            <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
                <add input="{REQUEST_URI}" pattern="^/(marketplace)" negate="true" />
            </conditions>
            <action type="Rewrite" url="/" />
        </rule>

        <rule name="Custom rewrite rule" patternSyntax="ExactMatch" stopProcessing="true">
    <match url="^services/control/status\?Id=(SO|so){1}([0-9]*)" />
    <action type="Rewrite" url="/orders/detail/{R:0}" appendQueryString="false" logRewrittenUrl="true" />
</rule>
</rule>
    </rules>        
</rewrite>

【问题讨论】:

    标签: redirect iis url-rewriting url-routing iis-8


    【解决方案1】:

    据我所知,url 模式与查询字符串不匹配。如果要获取查询字符串值,应该使用重写条件。

    详情,请参考以下规则:

                <rule name="QueryStringRue" stopProcessing="true">
                    <match url=".*" />
                    <conditions>
                        <add input="{QUERY_STRING}" pattern="^Id=([0-9a-zA-Z]*)" />
                    </conditions>
                    <action type="Redirect" url="https://example.com/orders/detail/{C:0}" />
                </rule>
    

    【讨论】:

    猜你喜欢
    • 2015-08-08
    • 1970-01-01
    • 2015-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-22
    • 1970-01-01
    相关资源
    最近更新 更多