Forum Moderators: phranque

Message Too Old, No Replies

HTTP_HOST vs SERVER_NAME

What's the difference?

         

ergophobe

6:38 pm on Jun 3, 2004 (gmt 0)

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



Normally HTTP_HOST and SERVER_NAME are the same, but currently I have a domain where there is a domain that is also a subdomain of another domain.

HTTP_HOST is the domain name, as expected, but SERVER_NAME is a subdomain on a parent domain.

SERVER_NAME = subdomain.domain1.com
HTTP_HOST = domain2.com

Both addresses are prefectly valid, I'm just trying to figure out why the difference.

Tom

jdMorgan

7:06 pm on Jun 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As implied by the variable names, HTTP_HOST is derived from the incoming HTTP request, and SERVER_NAME is the given name of the server, derived from the server config file.

Jim

ergophobe

9:33 pm on Jun 3, 2004 (gmt 0)

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



Okay, here's the thing I don't really get.

Again, I have
domain1.com
subdomain.domain1.com
domain2.org (which maps to subdomain.domain.com)

In PHP, I use either SERVER_NAME or HTTP_HOST to build absolute URIs.

When I visit

domain2.org/page

I would expect that server_name would be subdomain.domain1.com, since that's what it's set as in httpd. I would expect http_host to be domain2.org, since that's what it is in the request. And in fact, that's how it works.

Here's the part I don't get. When I visit

subdomain.domain1.com/page

I would HTTP_HOST to now be changed to subdomain.domain1.com, but in fact, it's still set to domain2.org.

So the HTTP_HOST value is coming from somewhere other than the http request. I'm assuming that there's some rewriting flag that transforms it in this case or something.

jdMorgan

10:34 pm on Jun 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Check to see if your server is configured with UseCanonicalName on -- That causes no end of troubles.

Jim

gergoe

11:28 pm on Jun 3, 2004 (gmt 0)

10+ Year Member



...and how about posting of these VirtualHost containers?

ergophobe

12:31 am on Jun 4, 2004 (gmt 0)

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



Thanks, I'll check it out if I can.

Unfortunately this weirdness is happening on a shared server, so I don't have that much control.