You can automatically redirect a web page to another URL using either HTML meta tags or JavaScript. Here's how to do it using both methods:
1. HTML Meta Tag Redirect:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="refresh" content="5;url=https://www.example.com"> <title>Redirecting...</title> </head> <body> <p>This page has moved to <a href="https://www.example.com">example.com</a>.</p> <p>If you are not redirected automatically, <a href="https://www.example.com">click here</a>.</p> </body> </html>
- In the <meta http-equiv="refresh" content="5;url=https://www.example.com"> line, content="5; means the page will redirect after 5 seconds. You can adjust the number according to your preference.
- Replace https://www.example.com with the URL you want to redirect to.
JavaScript Redirect:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="refresh" content="5;url=https://www.example.com"> <title>Redirecting...</title> <script> window.onload = function() { setTimeout(function() { window.location.href = "https://www.example.com"; }, 5000); // 5000 milliseconds = 5 seconds }; </script> </head> <body> <p>This page has moved to <a href="https://www.example.com">example.com</a>.</p> <p>If you are not redirected automatically, <a href="https://www.example.com">click here</a>.</p> </body> </html>
- In the JavaScript code, window.location.href = "https://www.example.com"; redirects the page to the specified URL after 5 seconds (5000 milliseconds).
- You can adjust the timing by changing the value in setTimeout().