Blog Post URL's

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
1 year ago
farhad_kzp wrote:

do you have any idea about 3.9 version?
Regards,

sorry. i need to figure out. i will let you know if i found
1 year ago
farhad_kzp wrote:

do you have any idea about 3.9 version?

do you only want to allow ../blog/xyz..? or you want to save seo url like blog/xyz   at database also?
i)
    public partial class GenericUrlRouteProvider : IRouteProvider
    {
        public void RegisterRoutes(RouteCollection routes)
        {
            //generic URLs
            routes.MapGenericPathRoute("GenericUrl",
                                       "{generic_se_name}/{*extra_slug}",
                                       new { controller = "Common", action = "GenericUrl" },
                                       new[] { "Nop.Web.Controllers" });

ii)
    public partial class GenericPathRoute : LocalizedRoute
    {
public override RouteData GetRouteData(HttpContextBase httpContext)
        {
            RouteData data = base.GetRouteData(httpContext);
            if (data != null && DataSettingsHelper.DatabaseIsInstalled())
            {
                var urlRecordService = EngineContext.Current.Resolve<IUrlRecordService>();
               var slug = data.Values["generic_se_name"] as string;
                var extraSlug = data.Values["extra_slug"] as string;

if you request like ../blog/xyz
slug will contain blog and extraSlug will contain xyz.
if you request like ../xyz
slug will contain xyz and extraSlug will contain null.
you can use your custom condition based on that
1 year ago
Rashed Khan wrote:

do you have any idea about 3.9 version?
do you only want to allow ../blog/xyz..? or you want to save seo url like blog/xyz   at database also?
i)
    public partial class GenericUrlRouteProvider : IRouteProvider
    {
        public void RegisterRoutes(RouteCollection routes)
        {
            //generic URLs
            routes.MapGenericPathRoute("GenericUrl",
                                       "{generic_se_name}/{*extra_slug}",
                                       new { controller = "Common", action = "GenericUrl" },
                                       new[] { "Nop.Web.Controllers" });

ii)
    public partial class GenericPathRoute : LocalizedRoute
    {
public override RouteData GetRouteData(HttpContextBase httpContext)
        {
            RouteData data = base.GetRouteData(httpContext);
            if (data != null && DataSettingsHelper.DatabaseIsInstalled())
            {
                var urlRecordService = EngineContext.Current.Resolve<IUrlRecordService>();
               var slug = data.Values["generic_se_name"] as string;
                var extraSlug = data.Values["extra_slug"] as string;

if you request like ../blog/xyz
slug will contain blog and extraSlug will contain xyz.
if you request like ../xyz
slug will contain xyz and extraSlug will contain null.
you can use your custom condition based on that


Thank you Sir.
yes, I only want to allow ../blog/xyz and /xzy (or sename) should goes to 404.
As far as I realized I should use extraSlug along with previous replies.

I created extraSlug variable in GenericPathRoute.cs and replace
"{generic_se_name}"

with
"{generic_se_name}/{*extra_slug}"

but in GenericUrlRouteProvider.cs we have
            routes.MapGenericPathRoute("BlogPostUrl",
                                       "blog/{generic_se_name}",
                                       new { controller = "Common", action = "GenericUrl" },
                                       new[] { "Nop.Web.Controllers" });

so based on previous replies, extraSlug will not fire in routing.
Many thanks.
1 year ago
farhad_kzp wrote:

so based on previous replies, extraSlug will not fire in routing.
Many thanks.

you should not change default BlogPostUrl. keep the default one.
you can add redirection logic like this
data.Values["controller"] = "Common";
data.Values["action"] = "PageNotFound";
return data;

if
urlRecord.EntityName.ToLowerInvariant() is equal "blogpost" and slug not equal "bolg"
1 year ago
Rashed Khan wrote:

urlRecord.EntityName.ToLowerInvariant() is equal "blogpost" and slug not equal "bolg"


Many Thanks, it Solved with your great help.
a quick help for those who have same problem:
in GenericUrlRouteProvider.cs you should define a dynamic route. so based on previous replies I modified routes like below:

            routes.MapGenericPathRoute("BlogPostUrl",
                                       "{urlPart}/{generic_se_name}",
                                       new { controller = "Common", action = "GenericUrl" },
                                       new[] { "Nop.Web.Controllers" });
            routes.MapLocalizedRoute("BlogPost",
                            "blog/{SeName}",
                            new { controller = "Blog", action = "BlogPost", },
                            new[] { "Nop.Web.Controllers" });

it simply say urlPart could be something lilke "blog" and generic_se_name is "SeName"
so I defined urlPart as a cast in GenericPathRoute.cs :
                var urlPart = data.Values["urlpart"] as string;

and due to Rashed Khan answer add if statement in GenericPathRoute.cs :

                var urlEntityType = urlRecord.EntityName.ToLowerInvariant();
                if (urlPart == null)
                {
                    data.Values["controller"] = "Common";
                    data.Values["action"] = "PageNotFound";
                    return data;
                }
                if (urlEntityType.ToString().Contains("blogpost") &&  !urlPart.ToString().Contains("blog"))
                {
                    data.Values["controller"] = "Common";
                    data.Values["action"] = "PageNotFound";
                    return data;
                }
1 year ago
Update:
sorry for my mistake in "if function", it should be as below because in a simple topic page urlPart was null and it used to go 404 page, so I update it as below:

                if (urlEntityType.ToString().Contains("blogpost") && urlPart == null) 
                {
                    data.Values["controller"] = "Common";
                    data.Values["action"] = "PageNotFound";
                    return data;
                }

Regards,
1 year ago
Rashed Khan wrote:

you can add redirection logic like this
urlRecord.EntityName.ToLowerInvariant() is equal "blogpost" and slug not equal "bolg"


Hi again, this problem seems want to kill me at the end :))
I follow the steps as above replies but now I have a problem:
I use a third party plugin which is use a URL like:
domain.com/ticketing/new-ticket
with my changes {urlPart} is ticketing and
{generic_blog_slug} is new-ticket !!!
so as this route dose not exist for this plugin it return 404
I will be grateful for any response.
1 year ago
I also implemented Rashed Khan solution (extra_slug)
but in this function

if (urlRecord == null )
                {
                    //no URL record found
                    data.Values["controller"] = "Common";
                    data.Values["action"] = "PageNotFound";
                    return data;
                }

urlRecord  is null.
Regards,
1 year ago
any idea?
I know this is an old topic but the problem still exist.
this is a common problem and most of SEO audit offer to determine URLs target with indicators like /blog/blogposturl or news/newsposturl and etc.
Regards,
1 year ago
@farhad_kzp you can use dotpick (https://www.jetbrains.com/decompiler/) or any dll decompiler to know about controller and action name of your 3rd party plugin and use this one

data.Values["controller"] = "3rdPartyControllerName";
data.Values["action"] = "3rdPartyActionname";
return data;
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.