是否可以设置一个基本的HTML页面以在加载时重定向到另一个页面?


当前回答

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Redirect to a page</title>
    </head>
    <body onload="window.location.assign('http://example.com')">

    </body>
</html>

其他回答

你应该使用JavaScript。将以下代码放在头标签中:

<script type="text/javascript">
 window.location.assign("http://www.example.com")
</script>

我还将添加一个规范链接来帮助您的SEO人员:

<link rel="canonical" href="http://www.example.com/product.php?item=swedish-fish"/>

您可以使用META“重定向”:

<meta http-equiv="refresh" content="0; url=http://new.example.com/address" />

或JavaScript重定向(请注意,并非所有用户都启用了JavaScript,因此始终为他们准备备份解决方案)

<script language="javascript">
  window.location = "http://new.example.com/address";
</script>

但如果您有选择,我建议您使用mod_rewrite。

据我所知,迄今为止,我所看到的所有解决这个问题的方法似乎都在历史中添加了老位置。要重定向页面,但在历史记录中没有旧位置,我使用替换方法:

<script>
    window.location.replace("http://example.com");
</script>

您可以通过HTTP状态代码301或302自动重定向。

对于PHP:

<?php
    Header("HTTP/1.1 301 Moved Permanently");
    Header("Location: http://www.redirect-url.com");
?>