Ad Code

How to redirect from an HTML page

Is it possible to setup a basic HTML page to redirect to another page on load?

here is the code you can place in html page to make it redirect

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

Note: Place it in the head section.

I would use both meta, and JavaScript code and would have a link just in case. Also, I think it is a good idea to set the meta rate to 1 for occasional circumstances where the browser ignores 0 value meta refresh.

<!DOCTYPE HTML>
<html lang="en-US">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="refresh" content="1;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 the <a href='http://example.com'>link to example</a>
    </body>
</html>
For completeness, I think the best way, if possible, is to use server redirects, so send a 301 in the header. This is easy to do via .htaccess files using Apache, or via numerous plugins using WordPress. I am sure there are also plugins for all the major content management systems. Also, cPanel has very easy configuration for 301 redirects if you have that installed on your server. It can not hurt to have the server-side solution as the primary method, and also use the client-side solutions suggested here at the same time.

Reactions

Post a Comment

0 Comments