1

I need to redirect a subdomain on my website to a third party HTTPS website. We have our website hosted on GoDaddy and I tried their subdomain forwarding mechanism but that didn't work. That's when I created a seperate subdomain (which created a folder with that subdomain name) on my hosting. I then placed an HTML file with this code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta HTTP-EQUIV="REFRESH" content="0; url=https://third-party-domain.com">
<title>Untitled Document</title>
</head>

<body>
</body>
</html>

But this didn't work. I then tried a .htaccess redirect using this:

Redirect 301 / https://third-party-domain.com

But this didn't work either. What am I doing wrong?

3
  • 1
    debug suggestion: does it work with http: instead of https:? May 9, 2012 at 16:00
  • Just tried that too and it didnt work :(
    – hpb
    May 9, 2012 at 16:10
  • 1
    Then the issue probably has nothing to do with https specifically. May be some kind of general redirection bug or restriction in either your code or hosting. May 9, 2012 at 16:34

1 Answer 1

1

Change the open body tag of your html to the following:

<body onload="window.location='https://third-party-domain.com';">

This will execute javascript to set the URL the window uses to the new URL provided. This won't work if javascript is disabled so you might want to include a link to the new URL. According to the W3C, the use of meta refresh to redirect users is discouraged because it's disorienting to the users.

If you have PHP, available on your host, simply replace the index file for the folder your subdomain points at with an index.php file containing only the following:

<?php
header('Location: https://third-party-domain.com', 301);
?>

This will send a 301 header to the user's browser and send them to the appropriate URL seamlessly.

2
  • What the W3C suggests is "disorientating to the users" is when a page (periodically) auto-refreshes, rather than an immediate redirect. I'm not saying a meta-refresh/redirect is a good thing, but a JavaScript redirect onload is probably no better (other than working when meta refreshes have been disabled in the browser). If you are going to do a JS redirect you'd try and do it immediately as the page starts to load. HOWEVER, as you suggest, a redirect in the HTTP response headers is far more preferable.
    – MrWhite
    May 9, 2012 at 22:16
  • @w3d I agree. The JS solution isn't perfect. Oddly enough some browsers seems to ignore META refresh so I'll use both + a link if I can't get it done server side. I generally prefer to use the server side header redirect because it's the way it was meant to be done by the HTTP specs. May 9, 2012 at 22:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.