.htaccess in the site root (often public_html for the primary domain). Create the file if it does not exist—the name starts with a dot.
Add:
olddomain.com and newdomain.com with your domains. The ^(www.)? part matches both www and non-www; keep the ? as shown.