If you want to redirect all pages of an entire site to the main page of another domain, add the following code to the file, on a single line.
RedirectMatch 301 (.*) https://www.yournewdomain.com/
If you want to redirect one page to another page, add the following code to the file, on a single line.
redirect 301 /old-file-name.htm http://new-websites.com/new-file-name.htm
If you want to redirect all non-www
requests to www
, all you need to do is add the following:
RewriteEngine On RewriteCond %{HTTP_HOST} !^www. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
If you want to redirect a www
site to a non-www
site, add the following:
RewriteEngine On RewriteCond %{HTTP_HOST} ^www.mydomain.com [NC] RewriteRule ^(.*)$ https://mydomain.com/$1 [L,R=301]
Make sure to replace “mydomain.com
” and other sample addresses with your own.