Forum Moderators: open

Message Too Old, No Replies

Directory redirection based on url

n00b question...

         

Sir_Twist

7:03 pm on Jun 15, 2006 (gmt 0)

10+ Year Member



I'm completely new to this forum and I apologize in advance for maybe asking a question that's been answered before. I just couldn't figure out a way to search for it that gave me the answer I wanted.

This is my situation:

I have three domains pointing to the same IP. At the moment I'm using a very simple web server that has almost no function at all nut it will suffice for the moment. Later I'm getting apache.

This is what I want to do:

Based on what url the user requested I want to redirect the browser to a subfolder so that a user that types "http://www.example-1.com" will end up in the /example-1 subfolder and a user that requests "http://www.exaple-2.com" will end up int the /exaple-2 subfolder although they both point to the same IP.

I've worked out that it's the document.url property I have to work wiht but I have no idea how.

Any takers?

Sir_Twist

7:20 pm on Jun 15, 2006 (gmt 0)

10+ Year Member



Oh... I forgot. I would also like this to be totally transparent to the user if possible, so that links etc look as they would if it was a real virtual domain on a real webserver.

jshanman

7:22 pm on Jun 15, 2006 (gmt 0)

10+ Year Member



This should work, although I'd hurry and get that Apache server running :)

if (document.location.href.indexOf("site1.com")) {
document.location = "http://www.mainsite.com/site1";
} else if (document.location.href.indexOf("site2.com")) {
document.location = "http://www.mainsite.com/site2";
}

- JS

jshanman

7:24 pm on Jun 15, 2006 (gmt 0)

10+ Year Member



Oh... I forgot. I would also like this to be totally transparent to the user if possible, so that links etc look as they would if it was a real virtual domain on a real webserver.

Then you'd need Apache or a server side solution (PHP,ASP.JSP)

- Js

Fotiman

7:26 pm on Jun 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



location.replace("http://example.com/yourdir/");

Fotiman

7:28 pm on Jun 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




if (document.location.href.indexOf("site1.com")) {
document.location = "http://www.mainsite.com/site1";
} else if (document.location.href.indexOf("site2.com")) {
document.location = "http://www.mainsite.com/site2";
}

Don't use that approach. It will break the users back button. Instead, use location.replace(), which replaces the page in the user's history so that when they hit back they won't keep hitting your redirection page.

Sir_Twist

3:11 pm on Jun 16, 2006 (gmt 0)

10+ Year Member



Thanks guys. I'll try that. It does seem a proper web server with virtual host support is the best approach in the long run though, so that's what I'm gonna do as soon as I'm done building my server.