httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Damian Meyer <apa...@damianmeyer.com>
Subject [users@httpd] combining mod_rewrite and mod_vhost_alias
Date Fri, 30 Jan 2004 09:58:33 GMT
Hi,

I am trying to move from a scenario with many thousand static 
<VirtualHost> blocks in a config to one where we use mod_vhost_alias.  
So far, that module works well.

The scenario is to have the document root for each host in 
/home/sites/d/o/m/domain.tld/www for a host called domain.tld.  That 
part, and the VirtualDocumentRoot and VirtualScriptAlias commands as 
below work well.  For example, a request for http://aaa.com/index.html 
returns /home/sites/a/a/a/www/index.html as expected.

Now for the hard part, I also want www.domain.tld to return the same 
index.html file, without having a symbolic link at 
/home/sites/w/w/w/www.domain.tld/ which defeats the purpose of splitting 
up into three layers of directories.  Hence my question about 
mod_rewrite:  How can I strip the www. off the hostname before passing 
it to mod_vhost_alias?

I have tried this solution with both HTTP_HOST and SERVER_NAME as the 
environment variables being modified in the RewriteRule - does the 
RewriteRule permit modification of these system environment variables or 
just ones you set yourself?  What variable does VirtualDocumentRoot use 
to get it's data for it's %N.M substitutions?

  RewriteEngine On
  RewriteLog "/usr/local/apache/logs/rewrite.log"
  RewriteLogLevel 3

  RewriteMap  lowercase  int:tolower
  RewriteCond  ${lowercase:%{HTTP_HOST}}  ^www\.(.+)$
  RewriteRule ^/(.*)$ /$1 [PT,E=HTTP_HOST:%1]

  VirtualDocumentRoot /home/sites/%1.1/%1.2/%1.3/%0/www
  VirtualScriptAlias /home/sites/%1.1/%1.2/%1.3/%0/cgi-bin

I do have a solution involving a redirect:

  RewriteMap  lowercase  int:tolower
  RewriteCond  ${lowercase:%{HTTP_HOST}}  ^www\.(.+)$
  RewriteRule ^/(.*)$ http://%1/$1 [R]

But I don't want to go down that path as in some rare cases I don't 
always have control over the DNS and can't guarantee that domain.tld 
resolves to the same IP as www.domain.tld.

Alternatively, is there a way to conditionally have two different calls 
to VirtualDocumentRoot depending on www.domian.tld versus domain.tld?  
For example (in pseudo code):

if HTTP_HOST matches ^www\.(.+)$ then
  VirtualDocumentRoot /home/sites/%2.1/%2.2/%2.3/%2+/www
  VirtualScriptAlias /home/sites/%2.1/%2.2/%2.3/%2+/cgi-bin
else
  VirtualDocumentRoot /home/sites/%1.1/%1.2/%1.3/%0/www
  VirtualScriptAlias /home/sites/%1.1/%1.2/%1.3/%0/cgi-bin
endif

Any ideas, gentlefolk?  This is Apache 1.3.29 on linux.

Kind regards
Damian Meyer


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message