重定向到另一个HTML页面

使页面自动重定向到单独文件夹中的不同HTML文件的语法是什么? 我所有的搜索都会返回如何从一个网站重定向到另一个网站。


其中之一将工作...

<html>
<head>
<title>A web page that points a browser to a different page after 2 seconds</title>
<meta http-equiv="refresh" content="2; URL=http://example.com/services/computing/">
<meta name="keywords" content="automatic redirection">
</head>
<body>
If your browser doesn't automatically go there within a few seconds, 
you may want to go to 
<a href="http://example.com/">the destination</a> 
manually.
</body>
</html>

...或者它可以用JavaScript来完成。 此JavaScript示例在4.5秒(4500毫秒)的延迟后在新浏览器窗口中打开新网站:

 <script language="javascript" type="text/javascript">
     <!--
     window.setTimeout('window.open("http://example.com/","newsite")',4500);
     // -->
 </script>

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


如果您使用Apache并且可以使用.htaccess文件,则应使用以下类型的重定向。 将以下内容添加到网站根目录中的.htaccess文件中。

RewriteEngine On
RewriteRule ^/oldfile_path/file_name.html$ /oldfile_path/file_name.html [R=301,L]

这具有非常快速且立即重定向的优点。 这也取决于你重定向的原因。 这是一种更持久的方法,因为它发送的HTTP 301状态代码表示文件已永久移动并导致许多浏览器缓存该请求。 您可以将代码更改为其他类似302的临时重定向。

否则,您可以按照其他人的建议使用HTML <meta>标记进行简单重定向:

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

默认情况下, content="5"会在5秒后重定向。 这会变慢,并不是所有的浏览器都支持它。 重定向也可以用您选择的服务器语言PHPNode.js等来完成。

链接地址: http://www.djcxy.com/p/15727.html

上一篇: redirect to another HTML page

下一篇: 301 redirect for site hosted at github?