httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph Gröver <>
Subject How to determine the "right" vhost in name based vhosting
Date Thu, 19 Sep 2013 14:39:19 GMT


We usually use name based virtualhosts with something like the following

NameVirtualHost  IP:80

<VirtualHost IP:80>
  ServerName main.domain.tld
  ServerAlias alias.domain.tld


<VirtualHost IP:80>
  ServerName www.domain.tld
  ServerAlias alt.domain.tld

Now I'm looking for a function which reliable returns the
host main.domain.tld if the first vhost is used (even if 
it is used as alias.domain.tld) and returns www.domain.tld
if the second one is used (even if under the name alt.domain.tld).

I know of two ways to do this:

1. ap_get_server_name

 This returns the right hostname if "UseCanonicalName" is set.
 But returns just the Host:-Header if it is off - which is the default.

2. server_rec structure

 The element server->server_hostname always returns the first vhost
 available for an ip address. So even if I use www.domain.tld it returns

So the first option depends on "UseCanonicalName", the second does
something else - which is not what I want.

Any other ways of doing this?
Or is there just the solution to force "UseCanonicalName" to "on"
and otherwise it won't work.

Can anybody enlighten me as to how this should be done?

Thank you, Greetings
Sitepark Gesellschaft für Informationsmanagement mbH
Rothenburg 14-16, 48143 Münster

Telefon: +49 251 482655-0, Telefax: +49 251 482655-55

Geschäftsführer: Thorsten Liebold
Amtsgericht Münster, HRB 5017

View raw message