Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

Javascript redirect from subdomain URL to domain page

Code snippet below - needs to be fixed - How?

Now when user submits http://courses.jamarlearning.com, user is sent to http://www.jamarlearning.com/index.html. This is set up by ISP subdomain

What I want is when user submits http://courses.jamarlearning.com user is sent to http://www.jamarlearning.com/courses.html in the same folder as index.html. Using file (courses.html) name did not work in subdomain string

Thanks for help with this.

Cheers, Jim

<script language="JavaScript">
<!-- Redirection of courses.jamar.learning.com -->
<!-- to jamarlearning.com/courses.html -->
<!--
if ( location.hostname == "http://courses.jamarlearning.com" ) {
      window.location = "http://courses.jamarlearning.com/courses.html";
} else if ( location.hostname == "courses.jamarlearning.com" ) {
      window.location = "courses.html";
} else {
      // build current content
}
    -->
</script>
0
MARSPATH
Asked:
MARSPATH
  • 4
  • 4
1 Solution
 
hieloCommented:
if ( /courses\.jamarlearning\.com/i.test(location.hostname) ) {
      window.location = "http://www.jamarlearning.com/courses.html";
}
0
 
MARSPATHAuthor Commented:
Script placed as shown sends to user to http://www.jamar.learning.com - not http://www.jamarlearning.com/courses.html

What's wrong?

<head>
....
</style>
<script type="text/JavaScript">
<!-- Redirection of courses.jamar.learning.com -->
<!-- to jamarlearning.com/courses.html -->
<!--
if ( /courses\.jamarlearning\.com/i.test(location.hostname) ) {
      window.location = "http://www.jamarlearning.com/courses.html";
}

<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
etc...
</head>
0
 
hieloCommented:
initially you wrote:
>What I want is when user submits http://courses.jamarlearning.com user is sent to ...

so that is what the script is doing; sending the users from http://courses.jamarlearning.com to http://www.jamarlearning.com/courses.htm

On your last post you are talking about a different url:
 http://www.jamar.learning.com

Perhaps this will help you:
<html><head>
....
</style>
<script type="text/JavaScript">
<!-- Redirection of courses.jamar.learning.com -->
<!-- to jamarlearning.com/courses.html -->
<!--
if ( /courses\.jamarlearning\.com/i.test(location.hostname) || /courses\.jamar\.learning\.com/i.test(location.hostname)) {
      window.location = "http://www.jamarlearning.com/courses.html";
}

<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
etc...
</head>
</html>
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
MARSPATHAuthor Commented:
Hello again,

What I want is when user submits http://courses.jamarlearning.com user is sent to http://www.jamarlearning.com/courses.html in the same folder as index.html. Using file (courses.html) name did not work in subdomain string

courses.jamarlearning.com is the correct URL. Both of the scripts below send the user to http://www.jamarlearning.com/index.html. Scripts are in <head>...</head> of http://courses.jamarlearning.com/index.html

The file I want users to see is: http://www.jamarlearning.com/courses.html

<!-- Redirection of courses.jamarlearning.com -->
<!-- to jamarlearning.com/courses.html -->
<!--
if ( /courses\.jamarlearning\.com/i.test(location.hostname) || /courses\.jamar.learning\.com/i.test(location.hostname)) {
      window.location = "http://www.jamarlearning.com/courses.html";
}

<!--

if ( /courses\.jamarlearning\.com/i.test(location.hostname) ) {
      window.location = "http://www.jamarlearning.com/courses.html";
}
0
 
hieloCommented:
I believe this is what you want.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/JAMARLearningHomeLayout.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<title>JAMAR Learning - Web Magic</title>
 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="CSS/jamarlearning.css" type="text/css">
<link rel="stylesheet" href="CSS/jamarlearningformat.css" type="text/css">
<link rel="stylesheet" href="CSS/jamarlearningmenus.css" type="text/css">
<script type="text/javascript" src="p7tm/p7tmscripts.js"></script>
<style type="text/css">
<!--
#Layer1 {
	position:absolute;
	width:200px;
	height:115px;
	z-index:1;
	left: 342px;
	top: 737px;
}
#Layer2 {
	position:absolute;
	width:198px;
	height:100px;
	z-index:1;
	left: 30;
	top: 520px;
	background-color: #FFFFFF;
}
-->
</style>
<script type="text/JavaScript"><!--
//Redirection of courses.jamarlearning.com
//to jamarlearning.com/courses.html
 
 
if( String(window.location.href).match(/([\/]?index\.html?)$/) )
{
	window.location.href = String(window.location.href).replace(RegExp.$1,'/courses.html');
}
 
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
 
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
 
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
 
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
 
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
 
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
</script>
<link rel="stylesheet" href="p7tm/p7tmbasic.css" type="text/css">
</head>
 
<body onLoad="P7_TMopen();MM_preloadImages('images/jamrlogo_f2.gif')">
<table width="210" align="left" cellpadding="16" summary="Layout Table">
<tr valign="top">
<td width="210" bgcolor="#87CEFA"><p align="center" class="biggernotestyle">JAMAR Learning <br>
Paris, TN 38242
<br>
</p>
  <div id="p7TMctrl">
    <p><a href="#" onclick="P7_TMall(0);return false">Show Menus</a> | <a href="#" onclick="P7_TMall(1);return false">Hide Menus</a></p>
  </div>
  <div id="p7TMnav">
    <div><a href="#" onclick="P7_TMenu(this);return false">+ Web Magic</a>
        <div><a href="web-magic.html">Web Site Magic</a></div>
    </div>
    <div><a href="#" onclick="P7_TMenu(this);return false">+ Design Notes </a>
        <div><a href="client-server.html">Web Site Design</a></div>
    </div>
    <div><a href="#" onclick="P7_TMenu(this);return false">+ Courses</a>
        <div><a href="courses.html">List of Courses </a></div>
    </div>
  </div>
  <p align="center" class="biggernotestyle">&nbsp;</p>
  <p align="center" class="biggernotestyle">Learning the Magic<br>
    of Web Site<br>
    Development
</p>
  <p align="center" class="biggernotestyle"><img src="images/LearningContactsf1.jpg" alt="JAMAR Learning Contacts" width="150" height="25" id="Image2" onClick="MM_goToURL('parent','LearningContactsList.html');return document.MM_returnValue" onMouseOver="MM_swapImage('Image2','','images/LearningContactsf2.jpg',1)" onMouseOut="MM_swapImgRestore()"></p>
  <div align="center">
      <p class="contentstyle">Web Design By <br>
      <a href="http://www.jamarassociates.com" onMouseOver="MM_swapImage('Image3','','images/jamrlogo_f2.gif',1)"><img src="images/jamrlogo.gif" alt="Visit JAMAR Associates" name="Image3" width="96" height="44" border="0" onMouseOut="MM_swapImgRestore()"></a></p>
  </div>
</table>
<div id="content_Layer"> <!-- InstanceBeginEditable name="EditRegion3" -->
 
  <div align="center">
    <p class="historystyle" style="font-size: xx-large"><br>
    Welcome to Jamar Learning </p>
    <div class="rightfloatingpicture"><img src="Images/jamarllearninglogo_f1.gif" /></div>
    <p align="left" class="biggernotestyle">Learning is the acquisition and development of memories and behaviors, 
      including skills, knowledge, understanding, values, and wisdom.</p>
    <p align="left" class="biggernotestyle"> It is the goal of education, and the product of experience. </p>
<p class="historystyle">Here you will learn the technology, art</a> and magic of web site design </p>
  </div>
<div id="InsertedLayer_01"><img src="Images/JimAtWorkSpace.JPG" alt="JAMAR Office"></div>
  <!-- InstanceEndEditable --></div>
</div>
 
</body>
<!-- InstanceEnd --></html>

Open in new window

0
 
MARSPATHAuthor Commented:
Script (1) below works in an interesting way - in local browser (IE7), local file URL (E:\Sites\JAMARLearning\index.html) sends me to local file URL (E:\Sites\JAMARLearning\courses.html) and remains in the loop.

Script (1) or (2) below have no effect when files (Dreamweaver template & index.html) are uploaded to remote server (GoDaddy.com)

-->
</style>
<!-- Script (1) -->
<script type="text/JavaScript"><!--
//Redirection of courses.jamarlearning.com
//to jamarlearning.com/courses.html
 
 
if( String(window.location.href).match(/([\/]?index\.html?)$/) )
{
      window.location.href = String(window.location.href).replace(RegExp.$1,'/courses.html');
}

<!-- Script (2) -->
<script type="text/JavaScript"><!--
<!-- Redirection of courses.jamarlearning.com -->
<!-- to jamarlearning.com/courses.html -->
<!--
if ( /courses\.jamarlearning\.com/i.test(location.hostname) || /courses\.jamarlearning\.com/i.test(location.hostname)) {
      window.location = "http://www.jamarlearning.com/courses.html";
}

My original goal remains unobtainable:

"What I want is when user submits http://courses.jamarlearning.com user is sent to http://www.jamarlearning.com/courses.html in the same folder as index.html."

What does work (always has) is 'when user submits http://courses.jamarlearning.com user is sent to http://www.jamarlearning.com/index.html'

Sorry for so many words, but hard to explain
0
 
hieloCommented:

if( String(window.location.href).match(/([\/]?index\.html?)$/) )
{
      window.location.href = 'http://www.jamarlearning.com/courses.html');
}
 
0
 
MARSPATHAuthor Commented:
Al;most there - thanks for all help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now