Apache rewrite rules.

Hi,
I am new to Apache but I have requirement as follows.
if the url is http://images/data1/templates/[rest of the url path] it should redirect to http:/172.20.224.23/templates/[rest of the url path]
if the url doesn't have "data1/templates" (mean http://images/[anyuri]\) it should redirect to http://images:8080/[rest of the url path].

I tried as below

RewriteCond %{REQUEST_URI} ^/dm5/Templates/.*
RewriteRule ^/dm5/Templates/(.*) http://172.20.224.23:80/templates/$1 [L]
 RewriteRule ^/(.*) http://images:8080/$1 [L]   

It is all the time redirecting to http://images:8080/[rest of the url path].

If i comment out "RewriteRule ^/(.*) http://images:8080/$1 [L] " then i am getting the error "File does not exist: " in htdocs folder.

Please help me how to achieve my requirement.

Thanks
Samba Damerla

Where exactly is your rewrite rule?

May be i didn't understood your question. The below are my rewrite rule i write this in Virtula_host section.

RewriteCond %{REQUEST_URI} ^/dm5/Templates/.*
RewriteRule ^/dm5/Templates/(.) http://172.20.224.23:80/templates/$1 [L]
RewriteRule ^/(.
) http://images:8080/$1 [L]

For this type of rewrite rules, I recommend you place it in the .htaccess file in the appropriate directory or directories and not in your virtual host configuration.