Home How to change category Url to dynamically for seo
Reply: 1

How to change category Url to dynamically for seo

Levent KAYA
1#
Levent KAYA Published in 2018-01-13 10:59:16Z

I am looking to do something like:

For categories where the Controller will be CategoryController

I am trying to avoid having something like www.mysite.com/category/some-category or www.mysite.com/product/some-product as I feel it will perform better on the SEO side.

Also dont want to change other links.

such as : mysite.com/account/login etc..

I followed this solution for the categories and it's working but other links changed.

How to intercept a Url to dynamically change the routing

for mysite.com/account/login turned to: mysite.com/?action=Login&controller=Account

And if possible I don't want to show ControllerName for any controller.

So the result should be like that:

For products:

www.mysite.com/some-product-name

www.mysite.com/some-other-productname

For Account controller

www.mysite.com/login

www.mysite.com/Register

For other controllers

www.mysite.com/terms-of-use

www.mysite.com/about-us

A POSSIBLE SOLUTION

public class DetailNameConstraint : IRouteConstraint
{
    public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
    {
        string category = "";
        if (values["category"].ToString().StartsWith("kiralik-"))
        {
            category = values["category"].ToString().ToLower();
            return true;
        }
        return false;
    }
}

ALSO Adding

 routes.MapMvcAttributeRoutes();

        routes.MapRoute(
            name: "Category",
            url: "{category}",
            defaults: new { controller = "Category", action = "Index" },
            constraints: new { username = new CategoryNameConstraint() }
        );

        routes.MapRoute(
            name: "CategoryDetail",
            url: "{category}",
            defaults: new { controller = "Category", action = "Detail" },
            constraints: new { username = new DetailNameConstraint() }
        );

        routes.MapRoute(
            name: "Default",
            url: "{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

AND FOR THE SEO

 [Route("UyeOl")]
    [AllowAnonymous]
    public ActionResult Register()
    {
        return View();
    }

So editing only RouteConfig is not enough.

codelover
2#
codelover Reply to 2018-01-13 11:54:17Z

First of all you should create seolink field on the table.

For example; product name : besiktas xl forma

seolink : besiktas-xl-forma

Pass seolink parameter in Category/Index action.

routes.MapRoute(
 "CategoryRoute",                                                                                
 "category/{seolink}",                                                   
 new { controller = "Category", action = "Index" }   

);

   routes.MapRoute(
 "LoginRoute",                                                                                
 "login",                                                   
 new { controller = "Account", action = "Login" }  
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.30655 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO