301 permanent redirect

To redirect any pages from a previous website to the home page of another, which one would be correct in the .htaccess file please? and would anything else be needed in the file?

Redirect 301 / http://www.newdomain.com/

Or:

RewriteEngine on

RewriteBase / RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

In case it helps, both domains are on the same server.

The first coding is correct you can use it to redirect your old domain to new one.
Just add the following line in the htaccess file.

Redirect 301 / http://www.newdomain.com/

You can also use the below coding to fix up the issue.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.net/$1 [L,R=301,NC]

Another, the online htaccess file creation using the online tool. Just add your preview domain and your new domain in the and the tool will create the coding.

I would recommend using a 302 temporary redirect while testing because once the permanent redirect is propagated it is extremely difficult to remove.

According to my opinion 1st code is correct for 301 redirection.