c# - 重写规则以重定向 URL
问题描述
我将 URL 创建为 - http://localhost:13490/level1/XYZ/hulhbgma79
试图将这个 URL 重定向到 - http://localhost:13490/level1/PQR/HttpHandler.ashx?Id=hulhbgma79
在上面给出的 URL 示例中
- level1 - 此名称根据条件、level2 或 level3 而变化。
- XYZ - 是虚拟模块。
- PQR 是保存 HttpHandler.ashx 的文件夹。
- Id 是可验证的查询字符串参数。
- hulhbgma79 是为查询字符串参数传递的值。
我已经为这种情况编写了如下规则-
<rule name="RewriteURL" stopProcessing="true">
<match url="^XYZ\/((([A-Za-z0-9]+)(\s|&)([^\/]+))|(([^\/]+)(\s|&))|([^\/]+))\/?$" />
<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>
没有按预期工作。
任何人都可以帮助我获得相同的解决方案吗?
解决方案
<rule name="RewriteURL" stopProcessing="true">
<match url="(level\d)\/XYZ\/((([A-Za-z0-9]+)(\s|&)([^\/]+))|(([^\/]+)(\s|&))|([^\/]+))\/?$" />
<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>
推荐阅读
- javascript - 如何从 react-native 中的异步函数中获取价值?
- python - 匹配日期的正则表达式(贪心)
- c++ - 如何在vscode中链接和包含来自不同目录的c ++标头
- java - Java 方法与构造函数参数比较
- c - 如何在C中使用可变参数#define函数的类函数宏
- android - 是否可以从原生代码 onFlutter 导航到页面?
- docker-machine - 无法使用 docker-machine 创建新的 docker 实例
- javascript - 无法从 JSON 字符串中删除键值对?
- vue.js - Vue绑定样式动态backgroundImage带参数使用asset
- java - 将 ASCII 表情符号转换为十六进制