Blog Post URL's

8 years ago
Hello All,

I am using Nop 3.10 and I wish to change the URL for each post. By default blog url is "mydomian.com/blog" and each post url is something like this "mydomain.com/myposttitle.

I am trying to use the following URL instead;

"mydomain.com/blog/myposttitle"

So far I have changed route on "GenericUrlRouteProvider.cs" file from;

routes.MapLocalizedRoute("BlogPost",
                            "{SeName}",
                            new { controller = "Blog", action = "BlogPost" },
                            new[] { "Nop.Web.Controllers" });

to;

routes.MapLocalizedRoute("BlogPost",
                            "blog/"+"{SeName}",
                            new { controller = "Blog", action = "BlogPost" },
                            new[] { "Nop.Web.Controllers" });

But this throws errors when I try to browse;
mydomain.com/blog/customer-service-client-service

The parameters dictionary contains a null entry for parameter 'blogPostId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult BlogPost(Int32)' in 'Nop.Web.Controllers.BlogController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters

I need to make some changes to "BlogController.cs" file but cannot figure out where.

Any help or advise will be much appreciated.
8 years ago
anyone ?
5 years ago
I know this is old, but we are looking to accomplish this as well.

Right now, blog posts URL are as follows website.com/name-of-blog-post

They would like it to be adjusted to website.com/blog/name-of-blog-post

We would also want the old URLS to redirect to the new ones.
4 years ago
Two changes need to occur. First, the change you made is valid. However, in the same file (GenericUrlRouteProvider.cs), you need to add the following snippet:


routes.MapGenericPathRoute("BlogPostUrl",
                           "blog/{generic_se_name}",
                           new {controller = "Common", action = "GenericUrl"},
                           new[] {"Nop.Web.Controllers"});
2 weeks ago
can you help how to redirect all old url to new one?
domain.com/blogposturl
should be redirect to
domain.com/blog/blogposturl
now there is duplicate url and both of them are available.
2 weeks ago
You can search the marketplace for a plugin
https://www.nopcommerce.com/en/extensions?searchterm=url+redirection

Yu can see other suggestions in prior posts (e.g. URL Redirection via web.config)
https://www.google.com/search?q=site%3Anopcommerce.com++redirect+all+old+url+web.config
2 weeks ago
Thank you by the way but I meant a source code solution.
2 weeks ago
farhad_kzp wrote:
by the way but I meant a source code solution.

You can change the source code to register a new route variant:
Make changes in the Presentation\Nop.Web\Infrastructure\GenericUrlRoute Provider.cs:
endpointRouteBuilder. MapDynamic ControllerRoute<Slug Route Transformer> (pattern);
//add a new one endpointRouteBuilder. MapDynamicControllerRoute<SlugRoute Transformer> ($"blog/{{SeName}}");
//update the route record: endpointRouteBuilder. MapControllerRoute("BlogPost", $"blog/{{SeName}}",
new { controller = "Blog", action = "Blogpost"});
//@nopTeam
2 weeks ago
Thank you Sir for your quick reply.
I use 3.9 version, can you help me how to modify routes in this version?
I've added a section like this:
            routes.MapGenericPathRoute("BlogPostUrl",
                                       "blog/{generic_se_name}",
                                       new { controller = "Common", action = "GenericUrl" },
                                       new[] { "Nop.Web.Controllers" });

and also modifed blogpost route to: (as previous replies)
            routes.MapLocalizedRoute("BlogPost",
                            "blog/{SeName}",
                            new { controller = "Blog", action = "BlogPost" },
                            new[] { "Nop.Web.Controllers" });

Thank you in advance.
2 weeks ago
Rashed Khan wrote:
by the way but I meant a source code solution.
You can change the source code to register a new route variant:
Make changes in the Presentation\Nop.Web\Infrastructure\GenericUrlRoute Provider.cs:
endpointRouteBuilder. MapDynamic ControllerRoute<Slug Route Transformer> (pattern);
//add a new one endpointRouteBuilder. MapDynamicControllerRoute<SlugRoute Transformer> ($"blog/{{SeName}}");
//update the route record: endpointRouteBuilder. MapControllerRoute("BlogPost", $"blog/{{SeName}}",
new { controller = "Blog", action = "Blogpost"});
//@nopTeam


do you have any idea about 3.9 version?
Regards,