SEO-friendly routing



I have a product details page in a standard (non-Commerce) EPiServer MVC site. The controller for the page populates the details using a query string parameter, so the URL looks like ('container' is an intermediate page in the hierarchy, which also shows content).

I want to add routing so that the URL is routed to the correct controller, and the product ID is passed to the controller.

I've tried partial routing, but this doesn't seem the right approach - I don't really want to relocate the page,just pass it a parameter from the route.

I've also tried using custom segments, but I'm not sure how the URL shoudl be defined in this case.

Whichever approach I try, I'm currently getting either 404's or redirect loops.

I'm sure this shouldn't be that difficult - any ideas anyone?

Thanks, Mark

Mar 29, 2016 21:41

Setting up your route something like this might work, assuming you controller is named ProductPageController and that you don't use /product/ in other url:s on the site

	 name: "ProductRouting",
	 url: "{language}/{node}/product/{productId}/{page}/{action}",
	 defaults: new { controller = "ProductPage", action = "ShowProduct", searchTerm = UrlParameter.Optional, page = UrlParameter.Optional }

And then you can add a ShowProduct method in you controller and retrive the id and load the correct view

public ViewResult ShowProduct(JobPage currentPage, string productId) {

	throw new NotImplementedException("load view for product " + productId);
Mar 30, 2016 16:34

Using IPartialRouter should work and it has the benefit of not needing to find a pattern or reserve the phrase "product" in the URL as long as have specific page type for this.

Can you post the code you were trying with?

Mar 31, 2016 21:13


Thanks for the tip - I ended up implementing a custom segment.

I was wondering about IPartial router, but the signature for the interface(IPartialRouter<T1, T2>) didn't seem right - although I hadn't tried it with T! the same type as T2.

Apr 01, 2016 9:51
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.