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


当前回答

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

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

其他回答

尝试使用:

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

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

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

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

将显示为

重新使用

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

只是为了更好地衡量:

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

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

这不需要任何JavaScript代码。将其写入HTML页面的<head>部分:

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

页面在0秒加载后,即可转到页面。

Razor引擎延迟5秒:

<meta http-equiv="Refresh"
         content="5; url=@Url.Action("Search", "Home", new { id = @Model.UniqueKey }))">

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

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