I've got a couple of domain names that I wish to visit one domain but parts of this domain.

# this is what I currently have
RewriteEngine On
RewriteCond %{HTTP_HOST} ^.*\.?foo\.com$ [NC]
RewriteRule ^.*$ ${domainmappings:www.foo.com} [L,R=301]

# rewrite map file
www.foo.com www.domain.com/domain/foo.com.php
www.bar.com www.domain.com/domain/bar.com.php
www.baz.com www.domain.com/other/baz.php.foo

However , I'd rather not need to have each domain participate the RewriteCond. I attempted

RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule (.*) http://%1/$1 [R=301,L]

but that is going to do it for each domain. I only want the domain names which are within the mappings file to redirect, after which continue onto other rewrites whether it does not match any domain names within the mappings file.

You're on course. What you need to do is make use of the pipe operator into the spotlight to ensure that you've got a catch-all.

RewriteCond ${domainmappings:%{HTTP_HOST}|NOTFOUND}    ^(.+)$
RewriteCond %1  !^NOTFOUND$
RewriteRule ^.*$ ${domainmappings:%1} [L,R=301]

The 2nd condition won't match when the host isn't within the list. You'll still suffer from the www prefix, and also the situation matching, but you get the drift.

I am close when i determined the the situation matching, but not able to determine the www prefix. Basically use the first below, it really works without www. Basically make use of the second one, it really works using the www. Basically use BOTH - neither work.

RewriteCond %{HTTP_HOST} (.*)$ [NC] # works for without www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] # works with www
RewriteCond ${domainmappings:%1|NOTFOUND} ^(.+)$ [NC]
RewriteCond %1 !^NOTFOUND$
RewriteRule ^.*$ ${domainmappings:%1} [L,R=301]

Any ideas?