Try:
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^view=([0-9]+)$ [NC]
RewriteRule ^viewGallery\.php$ http://www.mydomain.com/gallery/?view=%1 [R=301,NE,NC,L]
This is essentially what you have except you change the regex for the query string to capture the ID, then you can backreference it using %1
in the rule's target.
But, an easier way to do it is:
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^view=([0-9]+)$ [NC]
RewriteRule ^viewGallery\.php$ http://www.mydomain.com/gallery/ [R=301,NE,NC,L]
Simply remove the ?view=%1
part altogether. The rewrite engine will automatically append the query string to the end as long as you don't have a ?
in the target.