To redirect all requests to a different domain name, create a .htaccess file in your app's web root directory:
public/.htaccess
with the following contents:
RewriteCond %{HTTP_HOST} =OLDDOMAIN RewriteRule (.*) http://NEWDOMAIN/$1 [R=302,L]
The following .htaccess file will redirect requests for www.example.com to the same path at the domain example.com.
RewriteCond %{HTTP_HOST} =www.example.com RewriteRule (.*) http://example.com/$1 [R=302,L]
The following .htaccess file will redirect requests for example.com to the same path at the domain www.example.com.
RewriteCond %{HTTP_HOST} =example.com RewriteRule (.*) http://www.example.com/$1 [R=302,L]
You can also unconditionally redirect all requests regardless of the requested domain name. This means that no content at all will be served from your app. Every single request will be redirected.
You should only use this if the domain you are redirecting to is not part of the same app, otherwise you will create a redirect loop and requests will fail with an internal server error.
To have an unconditional redirect, just exclude the RewriteCond directive in the examples above.
The following file will redirect all requests to example.com.
RewriteRule (.*) http://example.com/$1 [R=302,L]