Forward subdomain to a port number

2 posts / 0 new
Last post
#1 Tue, 11/23/2010 - 15:17
JoeEarl09

Forward subdomain to a port number

I am trying to forward a subdomain to a specific port #.

Example: I have installed a jukebox server and it is using domain:port. Instead of using my domain:port I would like to use subdomain.domain.com and forward it to domain:port so I do not have to enter the port # to access the site. Is this even possible?

Tue, 11/23/2010 - 17:25
Locutus

Sure this is possible, using the magic of mod_rewrite. I suppose there's nearly nothing that you can't do with mod_rewrite. ;) It is also what Virtualmin itself uses to realize the forward of "webmail.mydomain.tld" to "https://mydomain.tld:20000".

Here's the syntax for the Apache config:

ServerAlias subdomain.domain.com
RewriteEngine on
RewriteCond %{HTTP_HOST} =subdomain.domain.com
RewriteRule ^(.*) h-t-t-p://domain.com:port/ [R]

Replace "h-t-t-p" with "http" of course when you enter it. Need to write it this way because otherwise this "suboptimal" forum software will auto-convert it to some nasty attempt to produce an a href link. :)

In addition, you need to configure your BIND DOMAIN to have "subdomain.domain.com" resolve to the appropriate IP address.

Topic locked