Introduction

As search engines are playing a major role in the number of visits to the site, it is definitely advisable to keep your site optimized to the search engines. There are multiple factors that impact the site to be properly search optimized. One of them is the URL for the site.

It’s better to have an URL which is human readable and easily understandable than an URL which is not.

Bad URL - http://localhost:42725/Home/ProductDetails/1

Good URL - http://localhost:42725/Home/ProductDetails/1-mac-book-pro

In the case of a good URL, the user will be able to get an idea of the page itself, unlike the bad one.

Let’s get started to create SEO (Search Engine Optimized) friendly URL using MVC.

Details

MVC is having Default route like “{controller}/{action}/{id}” where the “id” is normally a number which acts as a key for the record. 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.

How to modify the URL?

Here, we have added a route which is SEO friendly.

Let’s debug the application and review the results.

ASP.NET

You can see 2 sets of product details links.

First is default MVC URL. On the click of that link:

ASP.NET

The URL is not self-explanatory.

Let’s click on the second link, which will generate a custom URL.

ASP.NET

Here, the URL is self-explanatory.

It will increase the chances of appearing early in the search result over the previous URL.

Please let me know your feedback or suggestions.