By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,729 Members | 1,340 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,729 IT Pros & Developers. It's quick & easy.

How can I redirect requests based on host?

P: n/a
Hi,

I have two domains pointing to the same ISP hosted web site.
How can I redirect request for www.domain2.com to a sub-folder using header
field "host"?
Thanks a lot...

J-

Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Carved in mystic runes upon the very living rock, the last words of Jay
Shen of comp.lang.php make plain:
I have two domains pointing to the same ISP hosted web site.
How can I redirect request for www.domain2.com to a sub-folder using
header field "host"?


In your index file:

if (ereg("domain2.com", $_SERVER['HTTP_HOST'])) {
header("Location: /subfolder/");
}

After that of course you'll have to make sure all your links include the
subfolder path.

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
Jul 17 '05 #2

P: n/a
Alan Little wrote:

Carved in mystic runes upon the very living rock, the last words of Jay
Shen of comp.lang.php make plain:
I have two domains pointing to the same ISP hosted web site.
How can I redirect request for www.domain2.com to a sub-folder using
header field "host"?


In your index file:

if (ereg("domain2.com", $_SERVER['HTTP_HOST'])) {
header("Location: /subfolder/");
}

After that of course you'll have to make sure all your links include the
subfolder path.


I've heard that some browsers have trouble with the Location header if you don't
include the full url, but I'm not sure if which ones. You might want to try:

header("Location: http://www.domain2.com/subfolder/");

--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #3

P: n/a
In article <KO***************@newssvr14.news.prodigy.com>, Jay Shen's
output was...
Hi,

I have two domains pointing to the same ISP hosted web site.
How can I redirect request for www.domain2.com to a sub-folder using header
field "host"?


Surely your ISP can set up name-based virtual hosts under Apache?

http://httpd.apache.org/docs-2.0/vhosts/
Jul 17 '05 #4

P: n/a
Shawn Wilson wrote:
I've heard that some browsers have trouble with the Location header
if you don't include the full url,


The field value of the Location HTTP header must consist of an
absolute URL; a relative URL would contravene RFC2616, sec. 14.30.
Resultantly, relying on relative URLs working is unwise, despite
applications supporting them.

--
Jock
Jul 17 '05 #5

P: n/a
Similarly, if you're running Apache, you can do this without having to worry
about links by using mod_rewrite and checking what the hostname specified in
the URL was. Check out the documentation for mod_rewrite:

http://httpd.apache.org/docs/mod/mod_rewrite.html (Apache 1.3)
http://httpd.apache.org/docs-2.0/mod/mod_rewrite.html (Apache 2.0)

Hope that helps.

EE

"Eto Demerzel" <et**********@fijivillage.com> wrote in message
news:MP************************@news-text.blueyonder.co.uk...
In article <KO***************@newssvr14.news.prodigy.com>, Jay Shen's
output was...
Hi,

I have two domains pointing to the same ISP hosted web site.
How can I redirect request for www.domain2.com to a sub-folder using header field "host"?


Surely your ISP can set up name-based virtual hosts under Apache?

http://httpd.apache.org/docs-2.0/vhosts/

Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.