Can mod_rewrite Conditions/Rules be executed in random order?

Posted by Tom on Server Fault See other posts from Server Fault or by Tom
Published on 2012-07-03T19:53:55Z Indexed on 2012/07/03 21:17 UTC
Read the original article Hit count: 186

Filed under:
|

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

© Server Fault or respective owner

Related posts about apache2

Related posts about mod-rewrite