1

我正在学习 URL 重写,发现我们匹配传入请求的 URL,然后在匹配的基础上重写 URL,如下所示:

if (fullOrigionalpath.Contains("/Products/Books.aspx")) {
        Context.RewritePath("/Products.aspx?Category=Books");
    }
    else if (fullOrigionalpath.Contains("/Products/DVDs.aspx")) {
        Context.RewritePath("/Products.aspx?Category=DVDs");
    }

上面的书籍和 DVD 是类别。所以在这里我很困惑,如果用户添加了一个像计算机这样的新类别,那么会发生什么,或者我必须定期更新我认为好的条件。

4

1 回答 1

0

用户需要开发一个逻辑来将 url 映射到这样的页面。

假设包含产品和类别的 Url 然后重定向到带有查询字符串中的类别的产品页面

product/book.aspx
product/dvd.aspx
product/newcategory.aspx

product.aspx?category=book
product.aspx?category=dvd
product.aspx?category=newcategory

意味着最后您需要将任何类别重定向到

product.aspx?category=valueof category

下面是用 iis 重写的规则示例。

<rule name="Rewrite to Product" enabled="true">
<match url="^http://mysite.co.uk/Product/[0-9a-z-]+/([0-9]+)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="http://mysite.co.uk/Product.aspx?Category={R:1}" />
</rule>

有关更多详细信息,您可以访问Url Rewriting IIS

于 2013-09-16T11:29:16.310 回答