How to use mod rewrite forward to a new domain?

For examples, when we visit www.google.com, we want it redirect to https://kingphp.com, we can use the following code:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

The code posted above should be used on the old server.