首页 > 解决方案 > 重写规则以重定向 URL

问题描述

我将 URL 创建为 - http://localhost:13490/level1/XYZ/hulhbgma79
试图将这个 URL 重定向到 - 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-rewritingweb-config

解决方案


<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>

推荐阅读