If you want to redirect the user from one page to another automatically, you can use the syntax window.location.replace("page_url"). window.location and window.location.href. In this post we will show you two methods of redirecting a user to another page using vanilla JS. Sometimes a mistake, or poorly planned redirections, can cause an infinite sequence of redirects, redirecting back and forth between two or more pages. In this article we'll look at different ways we can use to redirect to a new web page (or a resource) using only JavaScript. Otherwise, it may be alright to issue a 404 – the reason being 1) we'd save up bandwidth from search engines trying to crawl and index a junk/stale page, and 2) we'd be able to inform the user about the error and display a search option and/or other relevant links instead (which may enhance the user experience).