Hi.
I have a project in asp.net mvc5 and I have a "Products" Controller.
I want to have these Urls:
for product list : "www.domain.com/Products"
for PDP page or one product page : "www.domain.com/Products/myproductName"
and also another PDP Url: "www.domain.com/Products/myproductID"
and for website SEO, I want to redirect permanent(302) "productID" Url to "productname" Url.
I have a "Index: action in my "Products" Controller and two "cshtml" view pages "Index" and "Product".
"Index.cshtml" is product list view and "Product.cshtml" is PDP view.
I added this route in my "RouteConfig.cs" file :
routes.MapRoute(
name: "Products",
url: "Products/{id}",
defaults: new { controller = "Products", action = "Index", id = UrlParameter.Optional }
);
This is my Action Code:
public ActionResult Index(string id)
{
if (string.IsNullOrEmpty(id))
{
var ProductList = repP.GetProductList();
return View(ProductList);
}
else
{
try
{
int pid = Convert.ToInt32(id);
var p = repP.GetProductByID(pid);
if (p != null)
return RedirectToActionPermanent("", "Products", new { id = p.prdxtraUrlTitle });
else
return RedirectToAction("");
}
catch (Exception)
{
var p = repP.GetProductByUrl(id);
if (p != null)
return View("Product", p);
else
return RedirectToAction("");
}
}
}
Now, what's my problem? Google Indexed for example this url of my website: www.domain.com/Products/Index/1
but I need to redirect this url to for example www.domain.com/Products/My-Software
But when I type www.domain.com/Products/1 or www.domain.com/Products/Index/1 after redirect, my browser address is : www.domain.com/Products/Index/My-Software instead of www.domain.com/Products/My-Software
1- what is the best way to solve this problem? Did I do it correctly?
2- If my code is correct, how can I remove "Index" from My Urls? productID and productName url. because google detect the content of these Urls are duplicate and this decreases website SEO score.
Thanks a lot.
What I have tried:
I told it in description part.