sbruyneel Posted March 9, 2006 Share Posted March 9, 2006 I found two codes for redirecting my index page to anther page automatically (one in html and one in java)IN HTML<HTML> <HEAD> <!-- Send users to the new location. --> <TITLE>redirect</TITLE> <META HTTP-EQUIV="refresh" CONTENT="10;URL=http://www.netmechanic.com"> </HEAD> <BODY> This page has moved. You will be automatically redirected to its new location in 10 seconds. If you aren't forwarded to the new page, <a href="http://www.netmechanic.com"> click here</a>. </BODY> </HTML> IN JAVA<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Document sans nom</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><HEAD><script language="JavaScript"><!--window.location="http://www.aimsoptronics.be";//--></SCRIPT></HEAD><body></body></html>But I would like to find a code which redirect to different pages in function of the domain name that the user typed. For exemple, if I have three domain names and one web space and if a customer type www.sitea.com the index page will redirect to a specified page and if he types www.siteb.com, the index page will redirect to another specified page. Can you help me? Thanks Link to comment Share on other sites More sharing options...
scott100 Posted March 10, 2006 Share Posted March 10, 2006 First off i wouldn't have the customer type anything because more often than not they will make a typo and the thing won't work, i'd recommend using a select list for them to choose from.It would work like so: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Document sans nom</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><HEAD><script language="JavaScript"><!--function redirect(val){window.location=val;}//--></SCRIPT></HEAD><body><form><select id="selection"><option value="http://www.google.com">Google</option><option value="http://www.yahoo.com">Yahoo</option><option value="http://www.w3schools.com">W3Schools</option></select><input type="button" value="Go" onclick="redirect(selection.value)" /></form></body> Link to comment Share on other sites More sharing options...
sbruyneel Posted March 10, 2006 Author Share Posted March 10, 2006 I Scott,Thank you for your code but this is not really my question.I have one webspace and 3 domain names linked to the index.html of my webspace. So if user want to go on one of my domain names, he will come on the same index page.I would like to find a code (html or java) that grab the domain name typed by the customer in the browser (one of the three domain name I have) and in function of the domain name, the index page will be redirected to different pages in the website.Regards Link to comment Share on other sites More sharing options...
Verminox Posted March 10, 2006 Share Posted March 10, 2006 In the head of your document add this: <script language="JavaScript">var redirect = []redirect[0] = ["http://OLDURLHERE.com" , "http://REDIRECTEDURLHERE.com"]redirect[1] = ["http://OLDURLHERE.com" , "http://REDIRECTEDURLHERE.com"]redirect[2] = ["http://OLDURLHERE.com" , "http://REDIRECTEDURLHERE.com"]for(n=0;n<redirect.lengh;n++){if( location.href = redirect[n][0] ){window.location=redirect[n][1];}}</SCRIPT> Explanation? Sure.Its just an array with the first value as the OLD URL and the second value as the NEW URL.Now, looping from 0 to the last array entry (redirect.length), you put a conditional redirect. (In this case looping for the variable n.That is, if the first value of the redirect (redirect[n][0]) is the current location (location.href), then the window is redirected to (window.location) the new location (redirect[n][1]) Link to comment Share on other sites More sharing options...
Webworldx Posted March 10, 2006 Share Posted March 10, 2006 Can you not set up the domain name server side to point to a certain place on the site? Link to comment Share on other sites More sharing options...
Verminox Posted March 10, 2006 Share Posted March 10, 2006 I think the topic starter wants to link to a free-hosted page like freewebs or something which he/she won't be able to point to.(I may be wrong of course) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now