Sometimes you need to redirect an old domain name to a new one. Since many websites use Apache, you can use the following htaccess snippet to handle the redirects for you. This snippet will handle redirecting all your sub-pages on your old domain to the same sub-pages on the new one.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^ [NC,OR]          # old domain without www
RewriteCond %{HTTP_HOST} ^ [NC]         # old domain with www
RewriteRule ^(.*)$$1 [L,R=301,NC] # new domain