Gannyaa -
Joined: 29 Sep 2006 Posts: 93 Location: Nelson, BC -- Canada
|
Posted: Sat Jan 06, 2007 8:27 am Post subject: Virtual Hosts, Javascript, Abyss X1 |
|
|
Virtual Hosts and Javascript
Here is a small tutorial explaining how to declare a new virtual host and how to associate it with a domain name using Javascript.
(I kinda used the same instruction structure for creating hosts by aprelium, after searching I noticed a PHP redirect function too that's a sticky... this does it with javascript although PHP may be better)
* create a directory in your hard drive where the files of the web site will be stored. In this example we'll use an Abyss Web server and that you will create a new directory (folder) called ''\website1\'' inside "c:\mysites\"
* create an ''index.htm'' file and ''index.js'' file with URL detect Javascript and redirect functions
* How to access it and test it.
>1> First Register YourDomain.com
* www.yourdomain.com must be a valid registered domain name. Use your registrar's tools, to configure yourdomain.com DNS name to point to your computer's IP address. Here you can have www.yourdomain1.com and www.yourdomain2.com or more point to the same IP address:
www.yourdomain1.com --> 24.67.88.103
www.yourdomain2.com --> 24.67.88.103
>> Create a Directory for ''/website1/'' and ''/website2/''
Copy your files and folders to those websites
You should have a directory like this when done..
c:\mysites\
|_ website1
|_ website2
|_ website3
|_ website4
>2> In the directory ''c:\mysites\ create a new index.htm and a new index.js file.
Copy the following HTML code into your ''index.htm'' document
Code: |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" ><head>
<script type="text/javascript" language='javascript' src='index.js'></script>
</head><body onLoad='ReDirectURL();' ></body></html>
|
Copy the following Javascript Code into your ''index.js'' document
Code: |
var yourdomainUrl = new Array (
new Array ('http://www.yourdomain1.com/' , 'website1/index.htm')
, new Array ('http://www.yourdomain2.com/' , 'website2/index.htm')
, new Array ('http://www.yourdomain3.com/' , 'website3/index.htm')
);
var thisURL = document.location.href;
function ReDirectURL() {
for (i=0;i<=yourdomainUrl.length; i++) {
if ( thisURL == yourdomainUrl[i][0]) { document.location.href = yourdomainUrl[i][0] + yourdomainUrl[i][1]; }
}
|
Your directory should look something like this.
c:\mysites\
|_ index.htm
|_ index.js
|_ website1
|_ website2
|_ website3
|_ website4
>3> Change yourdomain1.com to your real domain name in ''index.js''
If your real domain name is ''haidavision.no-ip.info'' then make the change as follows:
Code: | new Array ('http://haidavision.no-ip.info/' , 'website1/index.htm')
, new Array ('http://www.stuff4sale.com/' , 'website2/index.htm')
|
If your real domain name has more than one name ie
www.crescentbeachhouse.ca
crescentbeachhouse.ca
crescentbeachhouse.no-ip.info
then make the changes as follows:
Code: |
new Array ('http://www.crescentbeachhouse.ca/' , 'website1/index.htm')
, new Array ('http://crescentbeachhouse.ca/' , 'website1/index.htm')
, new Array ('http://crescentbeachhouse.no-ip.info/' , 'website1/index.htm')
|
Save the changes.
>4> Test ''yourdomain1'' and see if it is accessing ''website1''
Use an external website such as http://www.proxify.com or use your best friends computer across the street or next door to test if ''yourdomain1.com'' is accessible from the internet.
>5> That's it! _________________ Todd (Gannyaa)
http://iGannyaa.bebo.com/
http://haidavision.no-ip.info/gannyaa/newblog.htm |
|