【问题标题】:URL rewriting: how to configure rules for new categories addedURL重写:如何为添加的新类别配置规则
【发布时间】:2013-09-16 20:21:29
【问题描述】:

我正在学习 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 是类别。所以在这里我很困惑,如果用户添加了一个像计算机这样的新类别,那么会发生什么,或者我必须定期更新我认为好的条件。

【问题讨论】:

  • 请尝试编辑问题标题以提供有意义的名称。 URL 重写新手 似乎不是问题!!!

标签: asp.net url-rewriting


【解决方案1】:

用户需要开发一个逻辑来将 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

【讨论】:

  • 没关系,但是当管理员通过管理员应用程序添加新类别计算机时,将如何添加上述配置
  • 不需要每次都添加配置。您需要为始终遵循的页面制定 conman 规则。
猜你喜欢
  • 1970-01-01
  • 2012-01-18
  • 2014-04-26
  • 2017-01-02
  • 1970-01-01
  • 2013-03-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多