简体   繁体   中英

URL rewriting: how to configure rules for new categories added

I am learning URL rewriting and found that we match the URL of incoming request and then rewrite the URL on the basis of match something like this:

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");
    }

Above Books and DVDs are categories. so here i am confused that if a user adds a mew category like Computer then what will happen or i have to regularly update the condition which i done think is good.

User need to develop a logic to map the url to page like this.

suppose Url that contains product and category then redirect to product page with category in query string

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

to

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

means finally you need to redirect any category to

product.aspx?category=valueof category

below is the example of the rule in rewriting with 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>

For more details you can visit Url Rewriting IIS

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