Setting Up Subdomains on HTTP Alternate Ports (8080)

by tobychui in Circuits > Websites

2738 Views, 19 Favorites, 0 Comments

Setting Up Subdomains on HTTP Alternate Ports (8080)

2016-12-07_11-39-07.png

Recently, I bought myself a domain and I want to set up sub-domains for my web server. However, my server is running on Port 8080 which is not a standard port for HTML protocol and it is not possible to set up a sub-domain in the normal way. In this instructable, I will share the way to remove the port number in the url bar of your browser and add javascript based virtual sub-domains system to your web server.

Network Configuration

2016-12-07_11-36-28.png

The reason for my special web server port was due to another web server running in my local network which has already occupied the port 80 and I have no access to that server. Hence, to host my website on another server (or PC), I have to use a different port (Port 8080).

Domain Setup

2016-12-07_11-30-19.png

First, you have to buy your domain name. The one I am using is provided by no-ip.com. In the Host Setting, you can choose "Port 80 Redirect". This will make the domain name you type in (e.g. example.com) be directed to your real ip address(e.g. 123.456.789.10:8080) with the use of

Check the Result of Port Redirect After Your Setting Has Been Applied

2016-12-07_11-37-38.png

After 5 - 10 minute, your setting should be updated and the iframe div should be added to your web page when you enter your domain name in your browser URL bar as shown in the picture.

Create Files and Folders in Your "www" Folder

2016-12-07_11-50-37.png

As I was using WAMP Server as my web server, my web server's root folder was in C:/wamp/www. You can read more on "how to install wamp" on the following instructable. Here

  1. Create a folder for your sub domain.If you want to use download.example.com, just create a folder call "download" inside your root folder.
  2. Create a php named as "subdomains.php", the javascript will be placed inside this php
  3. Create an index.php or rename your index.html to index.php if you already have your own index.

Edit the Subdomains.php

2016-12-06_22-27-18.png

Open the subdomains.php with text editor. I use wordpad++ here for the example. You can download the zip file provided and change all the "example.com" inside to your own domain name. The javascript works as follow:

  1. Check if the url in your browser URL bar contains .example.com
  2. If yes, get the part of string between the "http://" and ".example.com"
  3. Redirect you to the new url: "http://example.com/(subdomain)"

For example, if you enter test.example.com, the javascript will try to redirect you to example.com/test/

UPDATES

On line 20 and 21 of the zipped subdomain.php, you can choose either keeping the URL in your browser URL bar unchanged (test.example.com) or update the URL in your browser URL bar to "example.com/test/"

Downloads

Modify Index.php to Include the New Javascript

2016-12-07_12-06-45.png

Open your index with wordpad++ or other text editor.

Add <?php include "subdomains.php"; ?> after <head> as shown in the picture.

Done

Now, you can type in (subdomain).(yourdomain) and the javascript will automatically redirect you to (yourdomain)/(subdomain).

Example:

video.example.com -> example.com:8080/video/

test.example.com -> example.com:8080/test/

IMUS Laboratory

Logo V4 black.png

This system was a by-product of the development of IMUS Online System.

No update or improvement will be made to this code as the development of sub domains redirection system was terminated by our laboratory. Use with your own risk.

Free to share and modify. If you have any question, feel free to comment below and I will reply as soon as I read your comment.