To redirect a domain we use various ways but using .htaccess file is one of the best and easy way to redirect your domain. It’s too easy to redirect your domain by using .htaccess file. You can even redirect single page or also full website using. Htaccess file.
To redirect your domain you have to upload .htaccess file in your root folder "public_html" folder. This redirect only works on Linux server only.
How to redirect domain using .htaccess 301 redirect:
Redirect a single page: you can also redirect a single page of your domain using .htaccess redirect. Apply this code in your .htaccess file and redirect your single page.
To redirect an entire site using .htaccess file: you can also redirect your whole website with using .htaccess file. To redirect the whole website apply this code.
This code is so helpful and you can move your website to one domain to another domain and also redirect site.
To redirect your domain you have to upload .htaccess file in your root folder "public_html" folder. This redirect only works on Linux server only.
How to redirect domain using .htaccess 301 redirect:
Redirect a single page: you can also redirect a single page of your domain using .htaccess redirect. Apply this code in your .htaccess file and redirect your single page.
Code:
Redirect 301 /oldpage.html http://www.domainname.com/newpage.html
ReRedirect 301 /oldpage.html http://www.domainname.com/newpage.html
Redirect 301 /oldpage2.html http://www.domainname.com/folder/ direct 301 /oldpage2.html
Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^olddomainname.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.olddomainname.com [NC]
RewriteRule ^(.*)$ http://newdomainname.com/$1 [L,R=301,NC]