How to redirect URL page with Javascript.
Javascript redirect does not return 301 permanent redirect status code.
Replace old page with redirection code with the URL of the page you want to redirect to.
old-page.html:
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
// Javascript URL redirection
window.location.replace("http://www.mydomain.com/new-page.html");
</script>
</body>
</html>
Search engines use the 301 status code to transfer the page rank from the old URL to the new URL.
Javascript redirection return http response status code: 200 OK.
So Javascript redirection is not search engine friendly and it is better to use other redirection methods that return status code: 301 Moved Permanently.
javascript-redirect-test.htm
<!DOCTYPE html>
<html>
<body>
<script
type="text/javascript">
// Javascript URL redirection
window.location.replace("https://www.rapidtables.com/web/dev/javascript-redirect.htm");
</script>
</body>
</html>
Press this link to redirect from javascript-redirect-test.htm back to this page: