Problem:
Setting multiple variables(%1-%9) in rewrite rules with RewriteCond will get rewritten by the subsequent RewriteCond for the same rewrite rule pack.
eg.
RewriteCond %{REQUEST_URI} ID([^/]+)
RewriteCond %{REQUEST_URI} ID2([^/]+)
RewriteRule ^/login.php /newlogin.php?NewID=%1&NewID2=%2
The above rule is not practical in real world, there are better ways to do this. But just as an example, we can see that in fact the %1 will be set in the first RewriteCond AND set again in the second RewriteCond. %2 will never be set. So this rewrite rule would never work.
Another limitation of this method is the maximum number of variables RewriteCond can set Max=9.
Possible solution:
Instead of that we can use the Environment variables in the following manner:
# Setting the new environment variables ID and ID2
RewriteRule ID([^/]+) - [E=ID:$1]
RewriteRule ID2([^/]+) - [E=ID2:$1]
# Using them to rewrite the new URL
RewriteRule ^/login.php /newlogin?NewID=%{ENV:ID}&NewID2=%{ENV:ID2}
This above rewrite rules will then rewrite:
http://my.server.com/login.php/IDmarcel/ID2smith
to
http://my.server.com/newlogin.php?NewID=marcel&MewID2=smith
If you are working with the Query_string for example you can use the following technique:
RewriteCond %{QUERY_STRING} ID=([^&]+)
RewriteRule ^/login.php - [E=ID:%1]
RewriteCond %{QUERY_STRING} ID2=([^&]+)
RewriteRule ^/login.php - [E=ID2:%1]
RewriteRule ^/login.php /newlogin?NewID=%{ENV:ID}&NewID2=%{ENV:ID2}
The above rewrite rules will redirect the URL:
http://my.server.com/login.php?ID=marcel&ID2=smith
to
http://my.server.com/newlogin.php?NewID=marcel&NewID2=smith