Redirect for subdomains and secondary domains
Your third rule…


# Prevent access to staging through secondary.com/staging and instead use staging.secondary.com 
RewriteCond %{HTTP_HOST} ^secondary.com [NC]
RewriteRule ^(.*)$ http://www.secondary.com$1 [L,R=301]



… is basically a sloppier version of your first rule with a misleading comment.

The remaining two mod_rewrite rules can be combined as:

# Canonicalize hostname of secondary domain
RewriteCond %{HTTP_HOST} ^$secondary\.com$|^(www\.)?secondary\.primary\.com$ [NC]
RewriteRule (.*) http://www.secondary.com/$1 [R=301,L]


Note that if your site supports HTTPS, the rule would redirect HTTPS requests to unencrypted HTTP.