简体   繁体   English

asp.net重写规则中的重写和重定向

[英]Rewrite and redirect in asp.net rewrite rules

I am really struggling to understand rewrite rules and why mine do not do as id expect.我真的很难理解重写规则以及为什么我的不符合预期。

I have 2 rules, and basically what I need to achieve is that it picks up my pretty URL, regardless of sub directory and then redirect to a specific folder.我有两条规则,基本上我需要实现的是它拿起我漂亮的 URL,无论子目录如何,然后重定向到特定文件夹。 This will then use an id, which is specified in the pretty URL to then hit the appropriate page in my solution.然后这将使用一个在漂亮的 URL 中指定的 id,然后在我的解决方案中点击相应的页面。

So, this rule should be able to grab anything that comes before the pretty URL and then redirect to the folder /gen1/ from the root directory.因此,这条规则应该能够抓取漂亮的 URL 之前出现的任何内容,然后从根目录重定向到文件夹 /gen1/。

<rule name="PokemonGen1Rule 1">
    <match url="^gen1-[\w-]*[^?]*-pkmid([\d]+)\.html" ignoreCase="true" />
    <action type="Redirect" url="^/gen1/{R:0}" />
</rule>

This rule should then catch the url as it hits the gen1 folder and use the id contained within the pretty url, to pass it is as a parameter to the pokemon.aspx page.然后,此规则应在 url 到达 gen1 文件夹时捕获它,并使用漂亮的 url 中包含的 id,将其作为参数传递给 pokemon.aspx 页面。

<rule name="PokemonGen1Rule 2">
    <match url="^gen1/gen1-[\w-]*[^?]*-pkmid([\d]+)\.html" ignoreCase="true" />
    <action type="Rewrite" url="/gen1/pokemon.aspx?pkmid={R:1}" 
    appendQueryString="false" logRewrittenUrl="true" />
</rule>

It doesnt work, yet in my brain i cant work out whats broken.它不起作用,但在我的大脑中,我无法弄清楚是什么坏了。 I've tried various different combinations of putting chevrons, and whatnot and it doesnt work.我尝试了各种不同的人字形组合,以及诸如此类的东西,但它不起作用。

Any suggestions would be greatly appreciated.任何建议将不胜感激。

<rule name="PokemonGen1Rule 1" stopProcessing="true">
    <match url="[\w-]*[^?]*/(gen1-[\w-]*[^?]*-pkmid([\d]+)\.html)" 
    ignoreCase="true" />
       <conditions>
         <add input="{REQUEST_URI}" negate="true" 
           pattern="/gen1/gen1-[\w-]*[^?]*-pkmid([\d]+)\.html" 
           ignoreCase="true" />
       </conditions>
   <action type="Redirect" url="/gen1/{R:1}" />
</rule>
<rule name="PokemonGen1Rule 2" stopProcessing="true">
    <match url="[\w-]*[^?]*/gen1-[\w-]*[^?]*-pkmid([\d]+)\.html" 
    ignoreCase="true" />
     <action type="Rewrite" url="/gen1/pokemon.aspx?pkmid={R:1}" 
     appendQueryString="false" logRewrittenUrl="true" />
</rule>

Solved it!解决了!

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

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