简体   繁体   English

IIS URL重写规则-测试有效,但没有结果

[英]IIS URL Rewrite rule - test works but no results

I'm having trouble writing a URL Rewrite rule for IIS 8.5. 我在为IIS 8.5编写URL重写规则时遇到麻烦。 My expertise writing rules is barely intermediate, and the documentation has not been helpful. 我的专业知识编写规则几乎没有中间内容,文档也无济于事。

I'm trying to redirect the following URL: 我正在尝试重定向以下URL:

hostname.com/sub1/sub2/sub3/sub4 hostname.com/sub1/sub2/sub3/sub4

to this URL: 到此URL:

hostname.com/sub1/sub6/sub7/sub2/sub4 hostname.com/sub1/sub6/sub7/sub2/sub4

And by that, I mean — 我的意思是-

  • hostname.com is a variable. hostname.com是一个变量。 There are multiple hostnames served by this single .NET application. 该单个.NET应用程序提供了多个主机名。
  • sub1 stays the same and is not a variable. sub1保持不变,并且不是变量。
  • sub2 is the sub that should trigger the pattern and is not a variable, however it gets moved to a different place in the URL. sub2是应该触发模式的子,它不是变量,但是它被移动到URL中的其他位置。
  • Given the previous two points, I assume the string 'sub1/sub2' should be hardcoded into the pattern to identify the URLs to transform and to avoid redirect loops. 考虑到前两点,我认为应该将字符串'sub1 / sub2'硬编码到模式中,以标识要转换的URL并避免重定向循环。
  • sub3 gets deleted. sub3被删除。
  • sub4 is a variable. sub4是一个变量。
  • sub6 and sub7 are not variables. sub6和sub7不是变量。

I know I'm using the term variable incorrectly - what I mean by variable is that those parts of the URL change and need to be captured and used as back references. 我知道我使用的术语“变量”不正确-变量的意思是URL的那些部分发生了变化,需要捕获并用作反向引用。

Let me clarify with an example: 让我用一个例子澄清一下:

https://hostname.com/application/catalog/v3g5h6j8k9/feline-footwear https://hostname.com/application/catalog/v3g5h6j8k9/feline-footwear

to -> 到->

https://hostname.com/application/showcase/default/catalog/feline-footwear https://hostname.com/application/showcase/default/catalog/feline-footwear

All my attempts at writing a rule failed. 我编写规则的所有尝试都失败了。 I'm sure I'm doing everything wrong. 我确定我做错了所有事情。

I thought I got close with this. 我以为我已经接近了。 The pattern tests all succeeded, but it would not pick up the incoming URL. 模式测试全部成功,但是不会获取传入的URL。 I just get a 404: 我刚得到一个404:

            <rule name=“Catalog redir” enabled=“true” stopProcessing="true">
                <match url=“^(.*)/application/catalog/(.*)/(.*)” />
                <action type="Redirect" url=“{R:1}/application/showcase/default/catalog/{R:3}” redirectType="SeeOther" />
            </rule>

I've also tried using ([a-zA-Z0-9_+-]+) instead of (.*) 我也尝试使用([a-zA-Z0-9 _ +-] +)代替(。*)

Also, I have this rule installed at the /application level of the tree, not the root. 另外,我在树的/ application级别(而不是根)上安装了此规则。 Could this be incorrect? 这可能不正确吗? Or better posed, how does the location of the rule in the web site tree correlate to the pattern? 或者更好的是,规则在网站树中的位置与模式如何相关? I couldn't find that in the docs either. 我也找不到在文档中。

Thanks in advance for any advice. 在此先感谢您的任何建议。

Placement of the rule within the tree, in regards to its format, was the issue. 问题在于规则在树中的放置方式。 Since it was not placed in the root, but was placed in /application, once I got rid of the first section, so that the beginning of the match url was application, it started working. 因为它不是放在根目录中,而是放在/ application中,所以一旦我摆脱了第一部分,那么匹配URL的开头就是application,它就开始起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM