如何使用 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-TW/web/dev/javascript-redirect.htm");
</script>
</body>
</html>
按此鏈接可從 javascript-redirect-test.htm 重定向回此頁面:
Advertising