Nick Mehrdad Babaki
Nick Mehrdad Babaki

Reputation: 12565

Beautiful Url and Umbraco routing

I have created a page in Umbraco 7.

I need to pass an id to this page and I want to read that parameter inside the template.

If I use this url: http://www.example.com/product?id=10 I have access to the id inside template using Request["id"] which is fine. but the issue is I want to have my Url like http://www.example.com/product/10 but if I use it I receive: "404 - File or directory not found.".

I actually thought it might be resolved by Umbraco default routing but it is not. I also tried IIS URL rewrite, but I believe it should be a better way in Umbraco to handle it same as ASP.NET MVC Routing.

Upvotes: 0

Views: 428

Answers (1)

You could use this rewrite rule to handle the routing before the request reaches Umbraco.

<rule name="Product Rewrite" stopProcessing="false">
          <match url="product/([0-9]+)/"/>
          <action type="Rewrite" url="/product/?id={R:2}"/>
</rule>

Another approach is to implement a custom ContentFinder which enable you "find" the content on your own. This allows you make even prettier urls for your products if you can determine the ids from the name in some way. This link https://24days.in/umbraco-cms/2014/urlprovider-and-contentfinder/ provide some information on how to implement a ContentFinder.

Upvotes: 1

Related Questions