redirect to another HTML page
What is the syntax for making a page auto-redirect to a different HTML file in a separate folder? All of my searching returns how to redirect from one website to another.
One of these will work...
<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>
...or it can done with JavaScript. This JavaScript example opens the new site in a new browser window after a 4.5-second (4500 ms) delay:
<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/">
If you're using Apache and can use a .htaccess
file you should use the following type of redirect. Add the following to an .htaccess
file in the root of your website.
RewriteEngine On
RewriteRule ^/oldfile_path/file_name.html$ /oldfile_path/file_name.html [R=301,L]
This has the advantage of being a very fast and immediate redirect. It also depends on your reason for the redirect. This is a more permanent method because it sends the HTTP 301 status code signifying that the file has moved permanently and causes many browsers to cache that request. You can change the code to something else like a 302 for temporary redirects.
Otherwise you can do a simple redirect using an HTML <meta>
tag as suggested by others:
<meta http-equiv="refresh" content="5; url=http://example.com/">
By default the content="5"
makes that redirect after 5 seconds. This will be slower and not all browsers support it. A redirect can also be done in the server language of your choice PHP
, Node.js
, etc.
上一篇: 永久重定向Github gh
下一篇: 重定向到另一个HTML页面