Redirecting a domain or URL is essential to keep the SEO rankings. Below are some of the common htaccess redirect rules which can be helpful to accomplish this.
Old site to New ste
In the root of your old Web server, edit or create a new .htaccess file using a text editor.
Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_HOST} ^www.old-domain.com$ [NC] RewriteRule ^(.*)$ http://www.new-domain.com/$1 [R=301,L]
A more common scenario is that your new domain has new files and directories. But you don’t want to lose the customers who remember the old domain and files. So, you should set up your mod_rewrite to redirect all the old files to the new domain:
RewriteRule ^.*$ http://newdomain.com/ [R=301,L]
Redirect the main domain to a sub-domain
RewriteEngine On Options +FollowSymlinks RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC] RewriteRule ^ http://sub.domain.com [R,L]
Redirect a domain to sub-folder
RewriteEngine On Options +FollowSymlinks RewriteBase / RewriteCond %{HTTP_HOST} www.domainname [OR] RewriteCond %{HTTP_HOST} domainname RewriteCond %{REQUEST_URI} !subfolder/ RewriteRule ^(.*)$ subfolder/$1 [L]
Redirect http to https
RewriteEngine on RewriteCond %{HTTP_HOST} ^domain.com$ [NC] RewriteCond %{SERVER_PORT} ^80$ RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L]
non-WWW to WWW
RewriteEngine On RewriteCond %{HTTP_HOST} ^domain\.com [NC] RewriteRule (.*) http://www.domain.com/$1 [L,R=301]