Script for domain redirection? ORZ (9)

1 Name: #!usr/bin/anon 2005-05-04 17:59 ID:DwuOgotf

The situation is this: I have two sites on my hosting account. The one is at the main address, and the other is inside a directory of that. I.e. it goes like this: site1.com and site1.com/site2.
I want to register a domain for site2, but the problem is that it looks like the hoster only supports domains which are linked to the main address.
So I wonder if it is possible to write some redirect script (html, or javascript, I don't really know) the purpose of which is to look which of the domains the visitor has entered into their browser, and depending on that info, either to redirect him to site2, or do nothing (=give content of site1)?

p.s. sorry for my very bad English orz

2 Name: !WAHa.06x36 2005-05-04 19:09 ID:q+2/dgia

Can you use mod_rewrite on your host? That sounds like one thing that could help you out, except that mod_rewrite has the worst syntax ever.

3 Name: dmpk2k!hinhT6kz2E 2005-05-04 22:29 ID:Xi+BfKj0

Normally you'd use ServerPath with virtual hosting. I doubt your host would be willing to modify their apache config though.

Another alternative is for your domain registrar to redirect with frames. Ie, site2.com would actually be site1.com/site2, but inside a 0-width frame. It works well enough, although it also borks bookmarking (any bookmark will always show site2.com only, not any subdirectories).

4 Name: #!usr/bin/anon 2005-05-05 10:16 ID:xNMwsRUY

Thanks for the tips.
Unfortunately, I think there's no support for virtual hosting here. And mod_rewrite support is buggy, somehow. Some of the clients have it working, others don't, although they often use the exactly alike .htaccess'es (just checked their forums). My account also seems to belong to the second category. :/ For the time being, managed to do this with javascript. Looks kinda ugly, but at least there's no problem with bookmarking.

5 Name: !WAHa.06x36 2005-05-05 15:57 ID:q+2/dgia

If you can set a PHP or Perl script as the index page on site1.com, you could fairly easily have that one redirect to different places depending on which site the user typed in.

6 Name: dmpk2k!hinhT6kz2E 2005-05-06 08:37 ID:3zrgQRmB

Might not work too well with relative addressing though if referrer is disabled. You'd have to make certain all links in the pages are absolute.

Certainly beats using a javascript hack.

7 Name: !WAHa.06x36 2005-05-06 10:42 ID:6jIGqKPo

>>6

I only meant that it could be used to do a single initial redirect when somebody types in site2.com. That's not ideal, but it's better than nothing.

8 Name: dmpk2k!hinhT6kz2E 2005-05-07 00:23 ID:FcGna8ol

Ah, I see what you mean. I don't see what's not ideal about it though, other than pages from both sites being accessible if you know where to look (like that really matters).

If redirects are such a bother, the perl file could always return a copy of the relevant base html. If it's set as index, nobody would ever be the wiser.

9 Name: Furi!EuK0M02kkg 2005-06-27 15:50 ID:Heaven

I like the idea of a redirect as well. Under PHP you just check the value of $_SERVER["HTTP_HOST"], if I remember correctly. If it comes up as site2.com, send a redirect to the relevant subdirectory. This of course is the next best thing after a proper rewriting that actually makes it look like you're always as site2.com

A PHP redirect is pretty similar in functionality to the services that redirect a domain name to a URL of your choice (ie. www.mysite.com then directs to www.isp.com/mysite/ and shows up in your browser), but this is cheaper. :)

This thread has been closed. You cannot post in this thread any longer.