Introduction: Setting Up Subdomains on HTTP Alternate Ports (8080)

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.

Step 1: Network Configuration

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).

Step 2: Domain Setup

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

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

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.

Step 4: Create Files and Folders in Your "www" Folder

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.

Step 5: Edit the Subdomains.php

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/"

Step 6: Modify Index.php to Include the New Javascript

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

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

Step 7: 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/

Step 8: IMUS Laboratory

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.

Comments

author
stalker145 (author)2016-12-07

Great instructable! I've never considered using javascript to direct traffic.

If you ever get access to the other server, using Apache redirects would definitely be preferable as there's less in the mix to go wrong.

https://httpd.apache.org/docs/trunk/vhosts/examples.html

author
tobychui (author)stalker1452016-12-08

Thanks, my friend in University also told me to use Apache redirect. But this is the final solution we came up :P

About This Instructable

309views

15favorites

License:

Bio: University student in Hong Kong, the only developer of IMUS Project. I love making something no one has thought of. If you like making things ... More »
More by tobychui:PLA 3D Prints Smoothing Research Project40000mAh LiPo Power BankArOZ System for Raspberry Pi Web Server
Add instructable to: