emitest2020 wrote:
example:
OLD PRODUCT URL | NEW SITE PRODUCT URL
/detail.asp?code=123456 | /wonderful-item-for-sale
is there a plugin where i can give the old link and new link and when a person arrives on a asp classic page, will be redirected to the new url ?
thanks
Have a look at how the "BackwardCompatibilityXXControllers" work in Nop.Web/Controllers and "BackwardCompatibilityXXRouteProviders" in Nop.Web/Infrastructure/.
You could create your own that routes on the old product "code" ID.
E.G.
public partial class BackwardCompatibilityASPController : BasePublicController
{
#region Fields
private readonly IProductService _productService;
private readonly IUrlRecordService _urlRecordService;
#endregion
#region Ctor
public BackwardCompatibilityASPController(
IProductService productService,
IUrlRecordService urlRecordService)
{
_productService = productService;
_urlRecordService = urlRecordService;
}
public virtual IActionResult RedirectProduct(string code, bool idIncludesSename = true)
{
if (string.IsNullOrWhiteSpace(code))
return RedirectToRoutePermanent("Homepage");
//we can't use dash in MVC, and parse out dangerous querystrings
var productId = idIncludesSename
? int.TryParse(code.Split(new[] { '-' })[0], out var numValue1) ? numValue1 : 0
: int.TryParse(code, out var numValue2) ? numValue2 : 0;
if (productId == 0)
return RedirectToRoutePermanent("Homepage");
var product = _productService.GetProductById(productId);
if (product == null || !product.Published)
return RedirectToRoutePermanent("PageNotFound");
return RedirectToRoutePermanent("Product", new { SeName = _urlRecordService.GetSeName(product) });
}
}
public partial class RedirectFromASP : IRouteProvider
{
public void RegisterRoutes(IRouteBuilder routeBuilder)
{
//products
routeBuilder.MapRoute("", "/detail.asp",
new { controller = "BackwardCompatibilityASP", action = "RedirectProduct" });
}
public int Priority => 1000;
}