I work for a small domain hosting company, and we currently host a few
hundred domains.  What I'm trying to do is have apache build the httpd.conf
file dynamically when it starts from a MySQL database.  Easy enough.  Got
most of it working, the only thing I'm running into is mod_rewrite problems.
Does anybody have any idea how to add the following:

RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^90.0.0.1$
RewriteRule .* http://www.whatever.com

to my current perl code (note - this isn't extracting info from the database
yet.  Just a simple text file for testing purposes):

<Perl>
  open(SC, "< /www/conf/virtual-domains.conf") || die "$!";
  while(<SC>) {
    chomp;
    next if(/^s*#/);
    my($sn,$sa,$ip,$htdir,$errlog,$translog) = split(/:/,$_,-1);
    $VirtualHost{$sn} = {
      ServerName   => $sn,
      ServerAlias  => "www.".$sn",
      DocumentRoot => "/www/virtual/".$htdir,
      ErrorLog     => "/www/virtual/".$htdir."logs/".$errlog,
      TransferLog  => "/www/virtual/".$htdir."logs/".$translog
    };
  }
  close(SC);
__END__
</Perl>

I'm thinking I can just add RewriteEngine => "on" to the VirtualHost hash.
But how do I handle the RewriteCond and the RewriteRule?  Can I make a hash
of hashes or something?  Maybe do something like:

RewriteCond => {'\%{REMOTE_ADDR}' => "!^90.0.0.1\$" },
RewriteRule => {'\.*' => "http://www.whatever.com" },

But that doesn't really work.  Just so you know, I've removed all of the
error checking for readability.  I didn't copy and paste this, so there
might be some syntax errors.  Anyway, if anybody can make a suggestion, or
point me at a web site I would appreciate it.  Thanks a ton in advance.

Brian Johnson
Systems Administrator/Programmer
Keweenet, LLC (www.keweenet.com)
Surgeon General announcement:
"Coffee is a direct substitute for sleep."

Reply via email to