Re: VirtualHost and ServerAlias

André Warnier <[email protected]>
Newsgroups gmane.comp.apache.mod-perl
Message-ID <[email protected]>
Vincent Veyron wrote:
> Hi Group,
> 
> I host a web service for my customers (ex : insurance_company.com) on a
> virtual host (*); my customers in turn want their customers (the
> policyholders) to have access to the data, while using their internet
> name instead of mine. 
> 
> This works fine with the ServerAlias directive inside the VirtualHost
> directive :
> 
>  ServerAlias extranet.insurance_company.com as-pro.biz
> 
> and the appropriate DNS settings.
> 
> That way, the policy holder can type
> 'http://extranet.insurance_company.com/clients/login' and have access to
> the data, transparently hitting my server at as-pro.biz.

Not really. I think you need to read up more on how VirtualHosts work.

> 
> My problem is the following : I have a handfulf of potential clients (3
> now, 6 at most), who all want the login form to the service customized
> with their logo. I cannot however know which logo to select before the
> user fills in the form.

Well, you can, because each customer (or customer of customer) presumably uses a different 
hostname to reach the server.

> 
> The names API :
> 
> http://perl.apache.org/docs/2.0/api/Apache2/ServerRec.html#C_names_
> 
> was apparently a solution for me, but it is not implemented in 2.0, and
> I am not able to code it.
> 
> Is there another way for me to pass to my PerlResponseHandler which
> ServerAlias was used? 
> 
> 
> (* : the service processes insurance claims for sick leaves; if you care
> to see what it looks like : 
> 
> http://as-pro.biz/clients/login?nom_utilisateur=152&amp;mot_de_passe=152
> 
> )
> 

It sounds like something which you could easily do in Apache itself, using the mod_rewrite 
module.  Make as many copies of your login page as you have customers, as 
login_customer1.html, login_customer2.html etc.. (with the correct logo in each).
Then set up your VirtualHost as follows:

RewriteCond %{HTTP_HOST} ^customer1.biz
RewriteRule "/login\.html$" "/login_customer1.html" [L]
RewriteCond %{HTTP_HOST} ^customer2.biz
RewriteRule "/login\.html$" "/login_customer2.html" [L]
etc..

At least that's the general idea.
Check this for details and more info.
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html

(of course you could also set up one VirtualHost per customer..)

To get the hostname which the client used to reach the server, use this :

$r->hostname
from
http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html#C_hostname_

This gives you the hostname that was mentioned in this request, not the one that is in the 
ServerName directive of the configuration section.
There is a difference.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.