SEO-friendly routing

Vote:
 

Hi,

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 www.mysite.com/container/product?productId=ABC123 ('container' is an intermediate page in the hierarchy, which also shows content).

I want to add routing so that the URL www.mysite.com/container/product/ABC123 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

#146887
Mar 29, 2016 21:41
Vote:
 

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

RouteTable.Routes.MapEnterpriseRoutes(
	 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);
			
}
#146912
Mar 30, 2016 16:34
Vote:
 

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?

#146964
Mar 31, 2016 21:13
Vote:
 

Johan,

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.

#146971
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.