问题描述
我会同时使用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 的配置非常简单。
尝试使用:
<meta http-equiv="refresh" content="0; url=http://example.com/" />
注意:将其放在头部。
此外,对于较旧的浏览器,如果您添加快速链接以防无法正确刷新:
将显示为
这仍然可以让您通过额外的点击到达您要去的地方。
解决方法
是否可以设置一个基本的 HTML 页面以在加载时重定向到另一个页面?