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


当前回答

只是为了更好地衡量:

<?php
header("Location: http://example.com", true, 302);
exit;
?>

确保脚本上方没有echo,否则将忽略它。http://php.net/manual/en/function.header.php

其他回答

JavaScript

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

Meta标记

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

我使用一个脚本将用户从index.html重定向到登录页面的相对url

<html>
  <head>
    <title>index.html</title>
  </head>
  <body onload="document.getElementById('lnkhome').click();">
    <a href="/Pages/Login.aspx" id="lnkhome">Go to Login Page</a>
  </body>
</html>

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

<script>
    window.location.replace("http://example.com");
</script>
<!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>

将以下代码放入<head>部分:

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