Redirect a WP to another with all URL

If you want 301/302 redirect sitewide my suggestion is to use .htaccess file, but that’s not a good practice at all. Anyway the code should be something like this

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^OLDDOMAIN\.com$ [NC]
RewriteRule ^(.*)$ http://NEWDOMAIN.com [R=301,L]

Note: Change the R=301 to whatever you would want where R=301 would mean permanent redirect and R=302 would mean temprorary redirect.

If you want to migrate your site to a new wp install on another domain, you need to use the WP Migrate DB plugin that can be found here : https://wordpress.org/plugins/wp-migrate-db/

The plugin do a really dirty job of replacing every single url in your db with a new one, which by hand is not really cool process.. You then need to import the db via phpMyAdmin or other interface to the new place and change all static links on the pages if there are any.