0

I am using IIS.net's Url Rewrite program on my server to make rules for URL Rewrite. I have pages on my Asp.NET 4.0 Web Site such as Page.aspx, and News.aspx.

When I create a rule for Page.aspx (http://www.foo.com/Page.aspx?PageTitle=Foo to http://www.foo.com/Foo) It works great.

When I create a rule for News.aspx (http://www.foo.com/News.aspx?NewsTitle=Foo to http://www.foo.com/Foo) It works great too.

But when I create rules for both News.aspx and Page.aspx, it fails. Program looks rule order. If News's rule is at top, News.aspx Url rewritten, and Page.aspx Url rewrite fails. If Page's rule is at top, Page.aspx Url rewritten, and News.aspx Url rewrite fails.

I guess thhis problem occurs because of regex matching. Let me show you:

enter image description here

Rule for News.aspx is at top. So it works fine. But when I click Page.aspx, the RewriteUserFriendlyURL1's Pattern catch my URL, and tries to redirect it News.aspx (Shown in Action Url).

I hope my description is clear.

My question is: How can I avoid this problem? For example I can make a new page called Redirect.aspx, and can redirect all pages to here. I can make 1 rule for Redirect.aspx.

But I think there should be another way to solve this issue with configuring these rules.

Thank you.

4

1 回答 1

0

问题是 RewriteUserFriendlyURL1 和 RewriteUserFriendlyURL2 的正则表达式完全相同,因此在这种情况下,它们的列出顺序决定了首先应用哪个规则。

我了解您要完成的工作,但它不能那样工作。URL 重写模块不可能知道/Foo是新闻文章还是页面。您最好的选择可能是将新闻放在下面/news/<title>并保留/<title>在您的常规页面中。在这种情况下,您可以使用/news/来区分新闻和页面。

因此,您应该保持 RedirectUserFriendlyURL2 和 RewriteUserFriendlyURL2 相同,但将 RedirectUserFriendlyURL1 的操作 URL/news/{C:1}更改为并将 RewriteUserFriendlyURL1 规则的模式更改为(注意:和^news/([^/]+)/?$之间没有斜线)。^news

于 2012-11-10T21:15:14.450 回答