I have some mod rewrite rules that test for the presence of a file on various NFS mounts and I would like that the tests occur randomly, as a very rudimentary way to distribute load.
For example:
RewriteEngine on RewriteCond %{REQUEST_URI} ^/(.+)$ RewriteCond /mnt/mount1/%1 -f RewriteRule ^/(.+)$ /mnt/mount1/$1 [L] RewriteCond %{REQUEST_URI} ^/(.+)$ RewriteCond /mnt/mount2/%1 -f RewriteRule ^/(.+)$ /mount2/$1 [L] RewriteCond %{REQUEST_URI} ^/(.+)$ RewriteCond /mnt/mount3/%1 -f RewriteRule ^/(.+)$ /mnt/mount3/$1 [L] RewriteCond %{REQUEST_URI} ^/(.+)$ RewriteCond /mnt/mount4/%1 -f RewriteRule ^/(.+)$ /mnt/mount4/$1 [L]
As far as I understand mod_rewrite Apache will look for the file on /mnt/mount1, then mount2, mount3 and so on.
Can I randomize this on each request? I understand this is an odd request but I need a creative solution to some unforeseen downtime.
On a side note, do I need to redeclare RewriteCond %{REQUEST_URI} ^/(.+)$
each time like I have done?
Thanks
As a suggestion, you can make a cron job that changes the file with the rewrites with other config file with the rewrite conditions in different order. You can run that cron job every minute and have different config files to replace it.
I think I found a feature in mod_rewrite that can accomplish this: RewriteMap prg
http://httpd.apache.org/docs/current/rewrite/rewritemap.html