IIS重定向规则未捕获指定的正则

发布于 2025-02-11 16:44:12 字数 1071 浏览 1 评论 0 原文

我正在尝试为我们的IIS服务器配置重定向规则。

我已经检查了网站上的所有文档以及其他几个示例,但是当模式匹配时,我似乎无法获取请求的URL来捕获。我尝试测试IIS规则编辑器内部的正则表达式,并表明它正确匹配。我还设置了一些条件并对其进行了测试,但是它似乎也行不通。

这是XML

<rule name="product_detail.asp redirect to aspx" stopProcessing="true">
    <match url="http:\/\/ten\.perle\.com\/products\/product_detail.asp\?(.*)&amp;(.*)&amp;(.*)" />
        <conditions>
           <add input="{QUERY_STRING}" pattern="http:\/\/ten\.perle\.com\/products\/product_detail.asp\?(.*)&amp;(.*)&amp;(.*)" />
        </conditions>
        <action type="Redirect" url="products/product_detail.aspx?{C:1}&amp;{C:2}&amp;{C:3}" appendQueryString="false" />
</rule>

示例url htttp:htttp:htttp: ///ten.perle.com/products/product_detail.asp?a=2& = 08000514&amp; c = 1650

我不明白我到底做错了什么,看起来我的回音看起来好像是我的regex应该抓住请求但是由于某种原因,它似乎从未如此。

I am trying to configure a Redirect Rule for our IIS server.

I have examined all the documentation as well as several other examples on the site, however I cannot seem to get the requested URL to capture when the pattern matches. I tried testing the regex inside the IIS rule editor and it shows that it matches correctly. I also set up some conditions and tested them however, it seems to not work either.

here is the rule in xml

<rule name="product_detail.asp redirect to aspx" stopProcessing="true">
    <match url="http:\/\/ten\.perle\.com\/products\/product_detail.asp\?(.*)&(.*)&(.*)" />
        <conditions>
           <add input="{QUERY_STRING}" pattern="http:\/\/ten\.perle\.com\/products\/product_detail.asp\?(.*)&(.*)&(.*)" />
        </conditions>
        <action type="Redirect" url="products/product_detail.aspx?{C:1}&{C:2}&{C:3}" appendQueryString="false" />
</rule>

sample url http://ten.perle.com/products/product_detail.asp?a=2&i=08000514&c=1650

I don't understand what exactly I am doing wrong It appears as though my regex should catch the request but for some reason it never seems to.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自此以后,行同陌路 2025-02-18 16:44:12

我觉得您的URL规则似乎存在一些问题。

例如,将请求发送到以下URL:
http://ten.perle.com/products/product_detail.asp?id=123&name = test

匹配URL中的模式应该是URL的路径部分:
产品/product_detail.asp

query_string服务器变量与URL的一部分匹配
参数字符串: id = 123&amp; name = test

您可以尝试修改规则并查看其是否有效。

此外,您可以使用失败的请求跟踪在IIS中进行故障排除。 failedreqlogfiles 文件夹中的日志文件可以查看整个重写的整个过程,并可以检查匹配失败的位置。

I feel like there seems to be some problem with your URL rule.

For example, Send a request to the following URL:
http://ten.perle.com/products/product_detail.asp?id=123&name=test

The Pattern in the Match URL should be the path part of the URL:
products/product_detail.asp

The QUERY_STRING server variable matches the part of the URL's
parameter string: id=123&name=test

You can try to modify your rule and see if it works.

In addition, You can use Failed Request Tracing in IIS to troubleshoot. The log file in the FailedReqLogFiles folder can see the whole process of rewriting in detail, and can check where the match fails.

秋叶绚丽 2025-02-18 16:44:12

因此,使用以下规则解决了该问题

<rule name="product_detail.asp redirect" stopProcessing="true">
    <match url="^(products/product_detail.asp?)([^x]+)$" />
    <action type="Redirect" url="products/product_detail.aspx?{R:2}" />
</rule>

,我想包括一些我想包含的东西,以防其他人面临类似的问题。有些事情要澄清。

  1. 匹配URL的部分应包括您将要重定向的URL的相对路径。在最初的尝试中,我不确定是否包括完整的路径或仅仅是相对部分。这在任何文档中都不清楚,至少它在我能找到的任何地方都没有明确说明。
  2. 重定向URL需要包含新URL基本URL之后所需的所有内容。包括参数,如果需要通过规则{r:x}或从条件{c:x}中拉出的参数,
  3. 我花了一些时间才能理解参数捕获,这是基于正则捕获的,如果您对其进行测试,它将向您显示如何显示URL匹配根据您的正则分解为编号的规则,
  4. 我最终不需要用用例的查询字符串条件,对我来说,使用初始模式捕获的规则捕获更为简单。

顺便说一句
希望这可以帮助其他一些希望这样做的初学者,并阐明IIS重定向的更多不太明显的方面。

So the Issue was solved using the below rule

<rule name="product_detail.asp redirect" stopProcessing="true">
    <match url="^(products/product_detail.asp?)([^x]+)
quot; />
    <action type="Redirect" url="products/product_detail.aspx?{R:2}" />
</rule>

Some things That I would like to include in case anyone else faces a similar issue. Some things to clarify.

  1. the match URL portion should include the relative path of the URL you're going to be redirecting. In my initial attempts I was unsure if to include a full path or just the relative portion. This isn't fully clear in any of the documentation, at least its not explicitly stated anywhere i could find.
  2. The redirect URL needs to contain everything required after the base URL for the new URL. Including parameters if required either pulled via rules {R:x} or from the conditions {C:x}
  3. It took me some time to understand the parameter capturing, this is based on the regEx, if you test it it will show you how the url match is broken up into numbered rules based on your regEx
  4. I ended up not need the query string condition for my use case, it was simpler for me to use the rules capture from the initial pattern.

also btw was working on IIS v10.0
Hope this helps some other beginners looking to do this and clarify some more of the less obvious aspects of IIS redirects.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文