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} ^olddomain.com [NC,OR]          # old domain without www
RewriteCond %{HTTP_HOST} ^www.olddomain.com [NC]         # old domain with www
RewriteRule ^(.*)$ https://newdomain.net/$1 [L,R=301,NC] # new domain