.htaccess redirect ALL traffic to another domain

.htaccess code:
redirect 302 / http://www.mynewdomain.com

you can also redirect access via PHP, using the header() function:

// Permanent redirect:
header('HTTP/1.1 301 Moved Permanently', true);
header('Location: http://www.location.com/');
// Temporary redirect (note that sending the 'Location' header automatically sends a 302 redirect unless it is explicitly overwritten, as it is above):
header('Location: http://www.location.com/');