/    Sign up×
Community /Pin to ProfileBookmark

URL redirect…

Ok, I made a thread before but i think its all tapped out..

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 begins with [url]www.unified[/url] and the other begins with [url]www.urbi[/url], 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?

[code]
function whichDomain()
{ var webAddress = location.hostname;
if (webAddress.substring(0,4) == “www.”)
{
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;

}
[/code]

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@scragarApr 29.2005 — [code=php]function whichDomain(){
var webAddress = location.hostname;
webAddress = webAddress.replace(/(http://)?(www.)?/, "");
if(webAddress.match(/^urbi/)){
return "r";
}else{
return "n";
};
};

function itemChooser(pageItem){
var returnString;
if(whichDomain()=="n"){
if (pageItem == "?"){
returnString = "?";
}
}else{
if (pageItem == "?"){
returnString = "?";
}

}

return returnString;

}[/code]
Copy linkTweet thisAlerts:
@noslenwerdauthorMay 02.2005 — [code=php]function whichDomain(){
var webAddress = location.hostname;
webAddress = webAddress.replace(/(http://)?(www.)?/, "");
if(webAddress.match(/^urbi/)){
return "r";
}else{
return "n";
};
};

function itemChooser(pageItem){
var returnString;
if(whichDomain()=="n"){
if (pageItem == "?"){
returnString = "?";
}
}else{
if (pageItem == "?"){
returnString = "?";
}

}

return returnString;

}[/code]
[/QUOTE]




? I'm still not sure what you did there? I'm sorry like i said im a n00b to JS so... i really dont understand the changes you made... or how it will boot up or redirect someone to the other URL?
Copy linkTweet thisAlerts:
@noslenwerdauthorMay 03.2005 — ok well thanks anyways... I can't figure it out ?
Copy linkTweet thisAlerts:
@ATBSMay 03.2005 — Don't give up. What are you having trouble with?
Copy linkTweet thisAlerts:
@noslenwerdauthorMay 04.2005 — ATBS

Thanks for your response...

I have all the structure laid out for the redirection that we were talking about in my other thread (the one where you said bestorlandorentals.com and bestflorida rentals.com etc. were all the same site)

I just need to know the syntax to put in my JS file to actually have a certail URL load after i validate which URL the person came in on?

For instance, this first function 'whichdomain()' i have is fine... I have no questions with that, but the Item choser function I need help with where i have ***

i know i need to include my js file that contains this code on my index.asp file, but i also need to know if i need any additional code in my index.asp file, and what that code would be

[code=php]
function whichDomain()
{ var webAddress = location.hostname;
if (webAddress.substring(0,4) == "www.")
{
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 == "?")
{
***Send them to www.unifiedsettlement.com/redirect.asp***;
}

}else{
if (pageItem == "?")
{
***Send them to www.urbistarsettlement.com***;
}

}

return returnString;

}[/code]
Copy linkTweet thisAlerts:
@noslenwerdauthorMay 05.2005 — ahhh ATBS you got my hopes up and let me down! haha.. just kidding
Copy linkTweet thisAlerts:
@ATBSMay 06.2005 — I gave you the site examples to help you understand how to use javascript to determine the url. The code I used to suit my purpose won't necessarily suit yours.

If I were you I'd probably call the function in the body onload event and you'll have to use something like: window.location.replace("whatever.html"); as the redirect.

Hope that helps.
×

Success!

Help @noslenwerd spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...