小编典典

从HTML页面重定向

html

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


阅读 1062

收藏
2020-05-10

共2个答案

小编典典

尝试使用:

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

注意:将其放在头部。

此外,对于较旧的浏览器,如果添加了快速链接以防刷新不正确,请执行以下操作:

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

将显示为

重新导向

仍然可以通过单击几下到达目的地。

2020-05-10
小编典典

我将同时使用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状态代码。通过.htaccess使用Apache的文件或使用WordPress的众多插件,这很容易做到。我确信所有主要的内容管理系统也都有插件。另外,如果您的服务器上安装了301重定向,则cPanel的配置非常简单。

2020-05-13