简体   繁体   中英

Issue with Similar Rewrite Rules in Web.config

I have a rule in my web.config that works.

<rule name="Guestbook Rewrite" stopProcessing="true">
<match url="(.*?)-guestbook" />
<action type="Rewrite" url="guestbook.asp?gb={R:1}" />
</rule>

When someone goes to MyDomain.com/view-guestbook or MyDomain.com/sign-guestbook they go to the appropriate pages.

What I am having difficulty with is that I have several pages of guestbook entries, so I want to be able to add a rule so that when someone goes to “view-guestbook-page-9” they are actually getting MyDomain.com/guestbook.asp?gb=view&pagenum=9. I had added the following rule, but as soon as I did I got 500 errors. I am going to guess that either it is in conflict with the previous rule or the syntax is incorrect.

<rule name="Guestbook View Page Rewrite" stopProcessing="true">
<match url="view-guestbook-page-(.*)" />
<action type="Rewrite" url="guestbook.asp?gb=view&pagenum={R:1}" />
</rule>

How can I have both rules or a single rule that would solve both?

I got it figured out. I had to add a condition to the first rule to not do anything for the other rule. So it looks likes this:

<rule name="Guestbook Rewrite" stopProcessing="true">
<match url="(.*?)-guestbook" />
    <conditions>
        <add input="{REQUEST_URI}" pattern="view-guestbook-page-" negate="true" />
    </conditions>
<action type="Rewrite" url="guestbook.asp?gb={R:1}" />
</rule>

<rule name="View Guestbook Page Rewrite" stopProcessing="true">
<match url="view-guestbook-page-(.*)" /> 
<action type="Rewrite" url="guestbook.asp?PageNum={R:1}" />
</rule>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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