Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

location.hostname redirection/validation ? 2

Status
Not open for further replies.

noslenwerd

Programmer
May 2, 2005
59
US
Hey all im a noob to the forums

Anyways, we are running a website with 2 different URLs, but the same exact content/IP and files. I started working on this js that will redirect users depending on which URL they enter through. Basically a company changed thier name, and wants users to go to a page (that i already created) that lets the user know the have changed thier name and website, then redirect them to the new URL.

But if they just go right to the correct/new URL, it just takes them to the index.asp file. And obviously i cant just make the page i created for the redirection and name it index.asp because it will change on both sites...

Here is the code i have so far, it is checking which URL they entered (the old one is and the other begins with hence the checking for the 'n' and 'r'). Problem is i need the syntax to actually send the person to the redirect.asp file when they enter the old url, and index.asp when they enter the new URL). What do I need to put in the if statements of my ItemChoser function, and also what what syntax should i put into the index.asp file if any?

Here is the code that i have so far...

function whichDomain()
{ var webAddress = location.hostname;
if (webAddress.substring(0,4) == " {
if(webAddress.substring(5,6)=="n")
{
return "n";
}
if(webAddress.substring(5,6)=="r")
{
return "r";
}

} // end if www
else
{
if(webAddress.substring(1,2)=="n")
{
return "n";
}
if(webAddress.substring(1,2)=="r")
{
return "r";
}

}
}

function itemChooser(pageItem){

var returnString;

if(whichDomain()=="n")
{
if (pageItem == "?")
{
returnString = "?";
}

}else{
if (pageItem == "?")
{
returnString = "?";
}

}

return returnString;

}

Thanks!!!
 
Try this:
Code:
if(location.href.indexOf('unifiedsettlement.com')>-1){
  location.href=location.href.replace(/unifiedsettlement\.com/gi','urbistarsettlement.com');
}

Adam

There are only 10 types of people in the world: Those who understand binary, and those who don't
 
But I would point the old domain to a different server that is completely empty, except for a custom 404 error page that redirects them.

Adam

There are only 10 types of people in the world: Those who understand binary, and those who don't
 
Ok thanks!

Just a little info, i just started this web development job 2 weeks ago and am fresh of of college so please bear with me...

The page i want them to see when they enter in unifiedsettlement.com is unifiedsettlement.com/redirect.asp

And the page I would like them to see if they enter in urbistarsettlement.com would just be the regular index.asp page (urbistarsettlement.com)

Could you show me exactly what the complete code would look like for that? Where would I put it? in the index.asp file, if so what part of the index.asp file

Thanks for your help and patience
 
This can be added to every page. It will redirect them to your redirect page with the url they are trying to visit added as a query string parameter:

Code:
if(location.href.indexOf('unifiedsettlement.com')>-1){
  location.href='redirect.asp?page='+escape(location.href.replace(/unifiedsettlement\.com/gi','urbistarsettlement.com'));
}

Then on your redirect.asp page, you can show them a message and redirect them after a few seconds to the url passed in the "page" parameter.

Adam

There are only 10 types of people in the world: Those who understand binary, and those who don't
 
ok here is exactly what i put into my index.asp file... should this work?

<script language="Javascript">
if(location.href.indexOf('unifiedsettlement.com')>-1)
{
location.href='redirect.asp?page='+escape(location.href.replace(/unifiedsettlement\.com/gi','urbistarsettlement.com'));
}
</script>
 
also i'm a little confused as to what

(/unifiedsettlement\.com/gi'

The gi part means here...

Thanks
 
Those are parameters for the regular expression.

g - global
i - ignore case

Do a google search for regular expressions to find more info.

-kaht

...looks like you don't have a job, so why don't you get out there and feed Tina.
[banghead]
 
Code:
function rgbConvert(str) {
   str = str.replace([COLOR=red]/rgb\(|\)/g[/color], "").split(",");
   str[0] = parseInt(str[0], 10).toString(16).toLowerCase();
   str[1] = parseInt(str[1], 10).toString(16).toLowerCase();
   str[2] = parseInt(str[2], 10).toString(16).toLowerCase();
   str[0] = (str[0].length == 1) ? '0' + str[0] : str[0];
   str[1] = (str[1].length == 1) ? '0' + str[1] : str[1];
   str[2] = (str[2].length == 1) ? '0' + str[2] : str[2];
   return ('#' + str.join(""));
}

To give a little more insight on the global parameter here's a function I wrote yesterday that required g at the end of the regexp. When returning color values in Firefox you get a string like this: rgb(255, 255, 255) instead of the traditional hex value: #ffffff. This function will take the Firefox color string and convert it into a hex color value. The first line takes the firefox color string and removes these parts of the string: rgb( and ). In the regexp that I wrote the first part searches for the rgb(

/rgb\(|\)/

and the 2nd part searches for the closing parentheses )

/rgb\(|\)/

Since I wrote one regexp to find either rgb( or ) I had to seperate them with the "or" operator |. Now, when the regexp is applied to the string it will first find a match to the rgb( portion of the string. Without the global parameter at the end of the regexp the match will be content. It found a match with rgb(, so it stops looking for anything else. After applying the global parameter to the regexp it continues looking thru the rest of the string to find any more matches. In which case it would find the closing parentheses ) and remove it as well, leaving you with a comma delimited set of numbers. (which is then split into an array, but that's a question for another thread [smile])

Hope that's a little more clear.

-kaht

...looks like you don't have a job, so why don't you get out there and feed Tina.
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top