3

A particular gaming platform allows clients to connect to game servers by entering a URL into their web browser. Upon entering the URL in the web browser and pressing enter, the application launches and joins the specified server. This URL takes the form of a specific application layer protocol, followed by an IP address and port. Ex. xyz://server-ip:port

I wish to redirect a subdomain of my website to the address of my game server. If my domain is example.com, I'm looking for play.example.com to redirect to xyz://server-ip:port.

Using a forward resource record did not work, nor did using a PHP header redirect, presumably because both are strictly HTTP redirects. Some ideas that I've had include using a <meta> tag, a .htaccess file, javascript, or another resource record, but I'm not familiar enough with any of them to know which, if any, are viable.

  • I'm surprised that a redirect response with a Location: header didn't work. The spec says that it can contain any URI, it doesn't limit it to just HTTP. – Stephen Ostermiller Dec 7 '16 at 15:26
  • I created a helper function identical to the one found in the top answer from this Stack Exchange question. Nothing would happen upon navigating to the index.php file. – Derek Ehle Dec 7 '16 at 15:48
  • @DerekEhle When you say nothing would happen... did it work with another, http URL? Was there an error of some sort (if error reporting was on)? Just to narrow down whether the issue might've been in the code instead... – Tim Malone Dec 8 '16 at 18:51
  • 1
    It was very finicky. When using another HTTP URL, I would get redirects around 10% of the time; sometimes it would correctly redirect a dozen times in a row, but it would always fall back to not redirecting. Similar results ended up occurring with the XYZ URL, but even less success. Maybe 5% of the time would navigating to the URL actually open the game application. I just don't understand why it was ambiguous. Shouldn't it either work 100% of the time or not at all? – Derek Ehle Dec 9 '16 at 19:43
2

Without knowing the specific game I can't test these, but here are a couple things to try:

First, try a proper Apache redirect in your virtualhost instead of a rewrite (I assume Apache since you mention .htaccess).

<VirtualHost *:80>

  ServerName play.example.com
  Redirect permanent / xyz://server-ip:port

</VirtualHost>

If that doesn't work, try framing the game page with an iframe. You'll need to create a virtualhost for play.example.com and serve a very basic index.html page with your iframe. This may work:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Title goes here</title>
    <!-- iframe may need some CSS to fit page, etc. -->
    <style>iframe{}</style>
  </head>
  <body>
    <iframe src="xyz://server-ip:port" ></iframe>
  </body>
</html>
  • I don't actually have access to virtualhost, as I am working in a shared hosting environment. I just confirmed this by submitting a help ticket with my hosting provider, with a link to this page as well. They said that while your answer seems pretty sound, it's not possible with my current shared hosting configuration. If I were to rent a full Virtual Dedicated Server, I would have full access to apache, and I could implement your solution. I gave you an upvote, but I'm still looking for alternatives since I cannot implement this without moving my site to a full server. – Derek Ehle Dec 9 '16 at 19:45
  • @DerekEhle You might also consider doing the redirect with your domain name Registrar. For example, Gandi.net offers redirects in the domain admin options page which can be used for a subdomain just as easily. I'm sure other Registrars offer similar functionality. You might also edit your question to add "...on shared hosting" because this makes a big difference. – Tom Brossman Dec 9 '16 at 20:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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