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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parsing URL and redirecting based on folder names

Status
Not open for further replies.

sheel331

Programmer
Joined
Mar 8, 2006
Messages
5
Location
US
Hello all,

I am brand new to coding javascript, and I am trying to code a redirect page based on the folder name. I have an IPlanet web server, and have begun to code this page. So far I have been able to split the URL based on the slashes '/'. Here is what code I have so far:

<HTML>
<BODY>
<script language="JavaScript" type="text/javascript">
<!-- hide from old browsers
var myURL, i, sheel;

myURL = document.URL;
document.writeln(myURL);

var myArray = myURL.split("/");
alert(myArray.length);

for(i = 3; i < myArray.length; i++)
{
document.writeln("<br> element is" + myArray + "<BR>");

document.writeln(myArray.length)
if (myArray.length > 3)
{
document.writeln(myArray.length)
document.writeln("<br>" + myArray[3])
}
else
{
document.writeln("<br>lets do something")
}
}
// -->
</script>
</BODY>
</HTML>

What I would like to do is take the folder name that the user is requesting, and redirect based on that. Any help is greatly appreciated.

Thanks,
Sheel
 
well, is the folder that you'd like to redirect on always in the same structure level? ie, is it always the fourth folder in?

[tt]www.somesite.com/which/folder/[red]thisone[/red]/do/you/want[/tt]



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Sorry to say, you will not be able to achieve this client-side, unless:

1. You have every possible combination of page and folder names possible with your code on them (very, very, unlikely), or

2. You have a 404 page that gives you these details.

Without either of these, how is your code ever going to be run?

I'd advise doing this server-side with a custom 404 page.

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Well, actually I am planning to do it as a custom 404 page server-side. So say a user accesses a page as it would take that as a 404 page, and then parse that URL, then redirect based on the 'sheel' subfolder.

It may not always be on the same level as well. It's possible that it would be that the URL could be and redirect only on the 'redirect' folder.
 
If you have the resources to build a custom 404 page, why on earth do you want to do this redirect client-side?

Do the whole thing server-side. That way it works for people with JS disabled, too.

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Dan,

I apologize for the confusion, but I am going to be doing this on the server, by coding this as a custom 404 page. The code above is what I have so far, and what I have in my head is that I would have an if loop that checks the folder name and redirect based on that.

Thanks,
Sheel
 
What server-side environment are you using - php, asp, jsp? I'd then suggest asking in the appropriate forum about customised 404s and whether there is a solution already available within that environment.

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Well, on IPlanet, the server-side platform I am forced to use is HTML, and I am embedding javascript into that code. that is why I am posting on this forum.

Thanks in advance,
Sheel
 
Your pages may reside on a server, and be delivered by a server, but HTML is NOT a server-side language.

Maybe you should find out if your host does support any server-side scripting or not. If it does not, you will not be able to achieve this [without an infinite number of pages].

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Maybe it is worth visiting the iPlanet Web Server Forum here on Tek-tips... forum42

I am fairly sure you can achieve this using a single 404 page and some server-side code (this is code that runs on the server before it delivers content to the browser). iPlanet has a built in Java engine which implies that it would run JSP server-side. Basically you would use Java (not Javascript) to code the 404 page and server-side decide what page to redirect the user to.

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Yes I did eventually fix my issue. Basically what i did was in the for loop, put a case statement in based on the first subfolder(which is the first element in the array). I then redirected based on that. Thanks for the help you provided.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top