Solved

Javascript redirect from subdomain URL to domain page

Posted on 2007-11-20
8
188 Views
Last Modified: 2012-05-05
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
Comment
Question by:MARSPATH
  • 4
  • 4
8 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 20320611
if ( /courses\.jamarlearning\.com/i.test(location.hostname) ) {
      window.location = "http://www.jamarlearning.com/courses.html";
}
0
 

Author Comment

by:MARSPATH
ID: 20321945
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
 
LVL 82

Expert Comment

by:hielo
ID: 20322542
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
 

Author Comment

by:MARSPATH
ID: 20330357
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 82

Expert Comment

by:hielo
ID: 20331046
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
 

Author Comment

by:MARSPATH
ID: 20335318
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
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 20335855

if( String(window.location.href).match(/([\/]?index\.html?)$/) )
{
      window.location.href = 'http://www.jamarlearning.com/courses.html');
}
 
0
 

Author Closing Comment

by:MARSPATH
ID: 31410138
Al;most there - thanks for all help
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now