Dear Wiki user, You have subscribed to a wiki page or wiki category on "Httpd Wiki" for change notification.
The following page has been changed by RichBowen: http://wiki.apache.org/httpd/RewriteMap ------------------------------------------------------------------------------ * RewriteMap prg: * RewriteMap dbd: or fastdbd: + For a description of the syntax, see [http://httpd.apache.org/trunk/mod/mod_rewrite.html#rewritemap Apache manual] + + == Problem: == + We want to map + {{{ + www.example.com --> /home/www/htdocs/hosts/www/ + the hostname www may be omitted from now on + www.sub1.example.com --> /home/www/htdocs/hosts/sub1/ + www.sub2.sub1.example.com --> /home/www/htdocs/hosts/sub1/sub2/ + www.sub3.sub2.sub1.example.com --> /home/www/htdocs/hosts/sub1/sub2/sub3/ + etc. + }}} + == Recipe: == + {{{ + RewriteEngine on + RewriteMap sub /physical/path/to/rwmap.pl + RewriteLock /var/lock/map.sub.lock + RewriteCond %{HTTP_HOST} ^(www\.)?([a-z.-]+)\.example\.com + RewriteRule ^/(.*) /home/www/htdocs/hosts/${sub:%2}$1 [L] + }}} + rwmap.pl: + {{{ + #!/usr/bin/perl + + $| = 1; + + while(<STDIN>) + { + chomp($_); + my @lables = split(/\./); + @lables = reverse @lables; + foreach my $label (@lables) { + $path .= $label . "/"; + } + print $path . "\n"; + } + }}} +
