Following works fine
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]
Now I need to do the same but with a directory, like
www.mydomain.com/oldname/something to www.mydomain.com/NEWNAME/something
Before the rule that redirects the domain, add these rules:
RewriteRule ^/?oldname/(.*)$ http://www.mydomain.com/newname/$1 [L,R=301]