I have a bit of a unique situation: I need to take a subdomain and make it redirect to a random selection of alternate domains, each of which is on a separate server. Think load balancing, except it's technically different from that.
Upon investigating my options, Apache's RewriteMap seemed like the ideal solution, except I can't seem to get it to do anything at all. Here's what I've got so far:
In my configuration file, I've added:
RewriteMap map "rnd:/home/mydomain/public_html/servers.txt"
This is in the server context, not VirtualHost or Directory. However, I do have "AllowOverride All" set for the public_html directory. And yes, I did remember to restart Apache after saving changes to my config.
Next, the servers.txt file itself:
servers domain1.com|domain2.com|domain3.com
(It doesn't really matter if these domains are exposed to the user, hence I'm just putting this in public_html for now, but I may move it elsewhere if I can get it working.)
Finally, I have an .htaccess file in public_html which already has several working Rewrite conditions and rules. RewriteEngine is on and all that. But when I add...
RewriteCond %{HTTP_HOST} ^subdomain.domain.com$
RewriteRule ^(.*)$ "https://${map:servers}/$1" [P,L]
... visiting my subdomain just shows the subdomain itself. I've tried a variety of different flags, but to no avail. At best, if I replace the [P] flag with [R=301] I can get a ERR_INVALID_REDIRECT response from the browser, which tells me the rule is at least being processed. Other than that, I don't even get any errors in Apache's error_log file. I've also made sure no other rules have the [L] flag, which might cause the new rule to be skipped.
As far as I can tell, according to the Apache documentation this is exactly the way RewriteMap is supposed to be used, so I'm a little perplexed to say the least. Can anyone tell me what I'm missing here?