I wanna make my urls SEO friendly.
I have seen a lot of articles and other posts on this subject, but all of them ends up with urls like: /Products/34/my-handbag
I wanna end up with urls like: /gucci/my-handbag
I already have the controls to actually get the product from the names “gucci” and “my-handbag”, i just need my routing to send me to Products
controller.
This is what I am working with right now:
routes.MapRoute(
name: "ProductDetails",
url: "{brand}/{title}",
defaults: new { controller = "ProductViews", action = "Details", brand = "", title = "" }
Any suggestions?
2
Answers
You’re on the right path. You can generate an url like:
http://www.domain.com/gucci/some-gucci-product-name by means of the following route.
You can handle the title, search for the product in db if it’s unique. If you have to add some unique number at the end of the url like;
http://www.domain.com/gucci/some-gucci-product-name-13456
Hope it helps.
@ali is right, but this structure is better-
You can remove the last word in stackoverflow and enter. The page redirects you to current and correct url. It is a better approach. My comments are:
If your website grows up, you can have same slug with different IDs and this is not limit to the problems that may appear. I know that it is not good for seo but it will happen.
In the backend you can have better performance to find product with ID and its important for high visited website.
It will be easy for you to change slug. If you change slug, old link will redirect to new link and you will not have any broken link.
In the backend find product with ID, then check the database to see if slug is equal to the parameter received from url. If it isn’t, you can redirect with 301 status to correct url, just like stackoverflow.