In my ASP.NET web application, I have defined custom error pages in my web.config file as follows:
I use javascript like
if (location.search != "") { window.location.href = "/404.html"; }