Can mod_rewrite Conditions/Rules be executed in random order?
- by Tom
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