It seems the problem is not with add_rewrite_rule
rather with the .htaccess
file for the multi site.
One of the test addresses was
http://example.com/foobar/def/whatever.php
Here’s a part of the htaccess which causes the result (Line 2)
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
If I comment this line out it works as expected but it may break other thing. So you have to add your own rule above the latest block:
RewriteRule ^([_0-9a-zA-Z-]+/)?foobar/(abc|def|ghi)/(.+)(/(\d.+))$ index.php?my_action=$2&my_name=$3&my_version=$5 [R=301,L]