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


当前回答

在HTML代码的<HEAD>和</HEAD>标记之间放置以下代码:

<meta HTTP-EQUIV="REFRESH" content="0; url=http://example.com/index.html">

上述HTML重定向代码将立即将访问者重定向到另一个网页。content=“0;可以更改为您希望浏览器在重定向之前等待的秒数。

其他回答

一旦页面加载,init函数就会启动并重定向页面:

<!DOCTYPE html>
<html>
    <head>
        <title>Example</title>
        <script>
            function init()
            {
               window.location.href = "www.wherever.com";
            }
        </script>
    </head>

    <body onload="init()">
    </body>
</html>

JavaScript

<script type="text/javascript">
    window.location.href = "http://example.com";
</script>

Meta标记

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

尝试使用:

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

注意:将其放在<head>部分。

此外,对于较旧的浏览器,如果您添加了一个快速链接,以防无法正确刷新:

<p><a href=“http://example.com/“>重定向</a></p>

将显示为

重新使用

这仍然允许您通过额外的点击到达您要去的地方。

我还将添加一个规范链接来帮助您的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。