Javascript 页面重定向

如何使用 Javascript 重定向 URL 页面。

Javascript 重定向不返回 301 永久重定向状态代码。

Javascript 重定向

将带有重定向代码的旧页面替换为您要重定向到的页面的 URL。

旧页面.html:

<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
    // Javascript URL 重定向
    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 重定向示例

javascript-redirect-test.htm

<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
// Javascript URL 重定向
window.location.replace("https://www.rapidtables.com/web/dev/javascript-redirect .htm");
</script>
</body>

</html>

 

按此链接从javascript-redirect-test.htm 重定向回此页面:


 

我要留言

    热门工具

 

    联系我们