【问题标题】:Rewrite rule to redirect URL重写规则以重定向 URL
【发布时间】:2019-03-05 03:35:29
【问题描述】:

我将 URL 创建为 - http://localhost:13490/level1/XYZ/hulhbgma79
试图重定向这个网址 - http://localhost:13490/level1/PQR/HttpHandler.ashx?Id=hulhbgma79

在上面给出的 URL 示例中

  1. level1 - 此名称根据条件、level2 或 level3 变化。
  2. XYZ - 是虚拟模块。
  3. PQR 是存放 HttpHandler.ashx 的文件夹。
  4. Id 是可验证的查询字符串参数。
  5. hulhbgma79 是为查询字符串参数传递的值。

我已经为这种情况写了如下规则 -

<rule name="RewriteURL" stopProcessing="true">
        <match url="^XYZ\/((([A-Za-z0-9]+)(\s|&amp;)([^\/]+))|(([^\/]+)(\s|&amp;))|([^\/]+))\/?$" />
          <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Redirect" url="{R:1}/PQR/HttpHandler.ashx?Id={R:9}" />

        </rule>

没有按预期工作。

任何人都可以帮助我获得相同的解决方案吗?

【问题讨论】:

    标签: c# url-rewriting web-config


    【解决方案1】:
    <rule name="RewriteURL" stopProcessing="true">
            <match url="(level\d)\/XYZ\/((([A-Za-z0-9]+)(\s|&amp;)([^\/]+))|(([^\/]+)(\s|&amp;))|([^\/]+))\/?$" />
              <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
              </conditions>
              <action type="Redirect" url="{R:1}/PQR/HttpHandler.ashx?Id={R:2}" />
    
            </rule>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多