How to customize URL routes for products and manufacturers?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
5 years ago
Hi,

I use nopCommerce 4.0. I would like the URL routes for Products and Manufacturers to display as follows:

www.mysite.com/products/product-123
www.mysite.com/manufacturers/manufacturer-123

I modified GenericUrlRouteProvider RegisterRoutes method as such

routeBuilder.MapLocalizedRoute("Manufacturer", "manufacturers/{SeName}", 
                new { controller = "Catalog", action = "Manufacturer" });


Now, in browser when I hover the mouse over the links, the tooltip displays the URL the way I want, i.e. www.mysite.com/manufacturers/manufacturer-123, but when I click the link I get 404 error :(
5 years ago
Here is one way to change the URL: https://www.nopcommerce.com/boards/t/26301/how-to-change-url.aspx
5 years ago
If you don't want to modify the source code, you should be able to do this with an URL Rewrite rule (in your web.config file)
5 years ago
A2Hosting_Liaison wrote:

Thanks, already tried that and was able to change /manufacturer/all to /manufacturers, however, that's an ID'less URL.
5 years ago
If you look into how customer profile page URL is displaying ID, you should be able to apply the same logic on products and manufacturers.
5 years ago
A2Hosting_Liaison wrote:
If you don't want to modify the source code, you should be able to do this with an URL Rewrite rule (in your web.config file)


I could modify the code, do you think this would require extensive modifications? Would you be able to point me to a documentation or blog page explaining how to do this?

A2Hosting_Liaison wrote:
If you look into how customer profile page URL is displaying ID, you should be able to apply the same logic on products and manufacturers.


Thanks, will look into that.
5 years ago
I found this: https://www.nopcommerce.com/boards/t/21708/product-route-add-the-id-parameter-problems.aspx

hope it helps
5 years ago
Try this article: https://www.pronopcommerce.com/nopcommerce-id-less-url-structure-demystified


5 years ago
I managed to get this to work by making the following changes:

In GenericPathRoute.cs


protected RouteValueDictionary GetRouteValues(RouteContext context)
{
   //remove language code from the path if it's localized URL
   var path = context.HttpContext.Request.Path.Value;

   if(path.StartsWith("/manufacturers/", StringComparison.OrdinalIgnoreCase)
      || path.StartsWith("/products/", StringComparison.OrdinalIgnoreCase))
   {
      path = path.RemoveLanguageSeoCodeFromUrl(context.HttpContext.Request.PathBase, false);
   }
   ...


In GenericUrlRouteProvider.cs


public void RegisterRoutes(IRouteBuilder routeBuilder)
{
    ...
    routeBuilder.MapLocalizedRoute("Product", "products/{SeName}",
                new { controller = "Product", action = "ProductDetails" });

    routeBuilder.MapLocalizedRoute("Manufacturer", "manufacturers/{SeName}",
                new { controller = "Catalog", action = "Manufacturer" });
5 years ago
vn0001 wrote:
I managed to get this to work by making the following changes:

In GenericPathRoute.cs


protected RouteValueDictionary GetRouteValues(RouteContext context)
{
   //remove language code from the path if it's localized URL
   var path = context.HttpContext.Request.Path.Value;

   if(path.StartsWith("/manufacturers/", StringComparison.OrdinalIgnoreCase)
      || path.StartsWith("/products/", StringComparison.OrdinalIgnoreCase))
   {
      path = path.RemoveLanguageSeoCodeFromUrl(context.HttpContext.Request.PathBase, false);
   }
   ...


In GenericUrlRouteProvider.cs


public void RegisterRoutes(IRouteBuilder routeBuilder)
{
    ...
    routeBuilder.MapLocalizedRoute("Product", "products/{SeName}",
                new { controller = "Product", action = "ProductDetails" });

    routeBuilder.MapLocalizedRoute("Manufacturer", "manufacturers/{SeName}",
                new { controller = "Catalog", action = "Manufacturer" });


That's great - Thanks for the update!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.