从 HTML 页面重定向

新手上路,请多包涵

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

原文由 chobo 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 600
2 个回答

尝试使用:

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

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

此外,对于旧版浏览器,如果您添加快速链接以防它无法正确刷新:

<p><a href="http://example.com/">Redirect</a></p>

将显示为

重定向

这仍然可以让您通过额外的点击到达您要去的地方。

原文由 Valerij 发布,翻译遵循 CC BY-SA 4.0 许可协议

我会同时使用 meta 和 _JavaScript 代码_,并且会有一个链接以防万一。

 <!DOCTYPE HTML>
<html lang="en-US">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="refresh" content="0; url=http://example.com">
        <script type="text/javascript">
            window.location.href = "http://example.com"
        </script>
        <title>Page Redirection</title>
    </head>
    <body>
        <!-- Note: don't tell people to `click` the link, just tell them that it is a link. -->
        If you are not redirected automatically, follow this <a href='http://example.com'>link to example</a>.
    </body>
</html>

为了完整起见,我认为最好的方法(如果可能)是使用服务器重定向,因此发送 301 状态代码。这很容易通过使用 Apache.htaccess 文件或使用 WordPress 的众多插件来实现。我相信还有适用于所有主要内容管理系统的插件。此外,如果您的服务器上安装了 cPanel,则它可以非常简单地配置 301 重定向。

原文由 Billy Moon 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题