如何使用 Javascript 重定向 URL 页面。
Javascript 重定向不返回 301 永久重定向状态代码。
Replace old page with redirection code 为您要重定向到的页面的 URL。
旧页面.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>
搜索引擎使用 301 状态代码将页面排名从旧 URL 转移到新 URL。
Javascript 重定向返回 http 响应状态代码:200 OK。
因此 Javascript 重定向对搜索引擎不友好,最好使用其他返回状态码的重定向方法:301 Moved Permanently。
javascript-重定向-test.htm
<!DOCTYPE html>
<html>
<body>
<script
type="text/javascript">
// Javascript URL redirection
window.location.replace("https://cmtoinchesconvert.com/zh-CN/web/dev/javascript-redirect.htm");
</script>
</body>
</html>
按此链接可从 javascript-redirect-test.htm 重定向回此页面:
Advertising