Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net MVC SEO Friendly URL

I want to implement a SEO friendly URL for my ASP.NET MVC website.

Currently i have a URL like:

http://www.domain.com/product?id=productid

but now i want to rewrite my URL like:

http://www.domain.com/productname

So please anybody can help me on above...

like image 491
Hitesh Bavaliya Avatar asked Feb 28 '13 06:02

Hitesh Bavaliya


People also ask

How can I get SEO friendly URL in asp net?

But to ensure the URL to be SEO friendly we need to change the “id” to contain a name. There can be multiple records with the same name existing in the database. That creates an issue while using a name of a record as “id” or key. Here, I will be using the name and id combination to get the uniqueness for the view.

Which URL is best for SEO?

URLs that are simple, easy to read, and include keywords that describe the content on a web page are SEO-friendly. For example, if you're searching for information about pancakes, a URL like https://en.wikipedia.org/wiki/pancake will help you decide to click on that link.

What is SEO friendly URL in SEO?

SEO friendly URLs are URLs that are designed to meet the needs of users and searchers. Specifically, URLs optimized for SEO tend to be short and keyword-rich.


2 Answers

You can add a Route to your MVC routing engine in this fashion -

In Global.asax.cs

routes.MapRoute(
    "Product",
    "{controller}/{productId}/{productName}",
    new { controller = "Product", action = "Index" },
    new { productId = UrlParameter.Optional , productName = UrlParameter.Optional  }
);

This will allow you to have URL like

www.domain.com/productid/productname

The reason you may or may not be able to achieve

www.domain.com/productname

is that productname isn't an identifier and cannot be used to lookup a record uniquely. You would need an identifier in the url.

Ex - look at the URL for this question in SO, it has the ID and then appends SEO friendly test.

like image 165
Srikanth Venugopalan Avatar answered Sep 29 '22 02:09

Srikanth Venugopalan


Please try with below solution. In global.asax.cs

routes.MapRoute(
    "Product",
    "{productName}",
    new { controller = "Product", action = "Index" },
    new { productName = UrlParameter.Optional  }
);

But you required to maintain uniqueness in productName and fetch record by that in index action of product controller (i.e in product Controller:

public ActionResult index(string productName)
{
     //do something regarding get product by productname
}
like image 42
Naresh Pansuriya Avatar answered Sep 29 '22 00:09

Naresh Pansuriya