-1

I want to redirect a plain HTML web page to a new URL, but everything I have tried (meta refresh, Javascript redirect) results in the old URL appearing in the address bar of the new page, even after clearing my browser cache. .htaccess redirects sometimes work but are complicated by the fact that the old page is already the target of a redirect from another domain. I do not have access to the hosting account.

Can anybody suggest a way to make the new URL always appear on the address bar for the new page? Thanks a lot.

tongro
  • 11
  • 4
  • Unless the page you are redirecting from was never directly displayed in the browser (e.g. if it was in a frame) then the behaviour you describe just won't happen. – Quentin Feb 01 '17 at 15:36

1 Answers1

-1

Using the meta refresh tag should work fine.

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

Note: Place it in the head section.

You may also want to do a javascript redirect as the W3C doesn't recommend the meta tag approach, although it may not work on all mobile browsers. Along with a fallback text link, that would make your page similar to:

<!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 this <a href='http://example.com'>link to example</a>.
    </body>
</html>

Many thanks to the answers from this previous answer: Redirect from an HTML page

Community
  • 1
  • 1
Andy
  • 698
  • 12
  • 22
  • Although your answer is 100% correct, it might also become 100% useless if that link is moved, changed, merged into another one or the main site just disappears... **:-(** Therefore, please [edit](http://stackoverflow.com/posts/41983652/edit) your answer, and copy the relevant steps from the link into your answer, thereby guaranteeing your answer for 100% of the lifetime of this site! **;-)** You can always leave the link in at the bottom of your answer as a source for your material... – Donald Duck Feb 01 '17 at 15:49
  • Thanks, but as I said, neither of those approaches works. For example, I'm redirecting http://example.com to http://example.net - the redirection works, but in the address bar of the browser (tested on Firefox and Chromium) appears "http://example.com". – tongro Feb 01 '17 at 20:07
  • Then, as @Quentin mentioned, I would wonder if you are viewing it in an HTML frame which is redirecting the visible content but masking the URL. Some webhosts do this on their web forwarding if you are using something like that. – Andy Feb 01 '17 at 20:24
  • No, I'm not using frames. Thanks. – tongro Feb 01 '17 at 22:07
  • Please could you edit your question to include your source code – Andy Feb 01 '17 at 22:11
  • I've decided to give up using client-side redirection and just use .htaccess, but the problem remains. However, that is a matter for another post. Thanks for the contributions. – tongro Feb 01 '17 at 22:59