Replace your rule with this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?maindomain\.com$ [NC]
RewriteRule ^(htatest/.+?\.(?:jpg|png))$ http://cdn.cdn.com/$1 [L,R=301,NC]