How to Redirect One Domain Name to Another Domain Using .htaccess
And here’s one I’m adding since it’s so useful… redirecting everything from an old domain to a new domain (not just the home page) so that you don’t lose traffic from bookmarks, links and search engine results. This one’s important to have on hand. You’ll use this if you change domain names or more content from an old domain name to a new one.
RewriteEngine on RewriteRule ^(.*)$ https://www.yournewdomain.com/$1 [R=301,L]
Just put that in your .htaccess file (or create one if you need to) and I suggest right at the top of the file to speed things up and everything coming to the domain name the .htaccess file sits on will be directed to the website (URL) you list above.
The example shown below is for both the www version of your domain and the non-www version of your domain.
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.yourolddomain.com [nc]
RewriteRule (.*) https://www.yournewdomain.com/ [R=301,L]
RewriteCond %{HTTP_HOST} ^yourolddomain.com [nc]
RewriteRule (.*) https://www.yournewdomain.com/ [R=301,L]Redirect All Pages to a New Domain (Catch-All)
Here’s one I call a “catch all” where it redirects all pages from an old domain to a new domain (single page).
This is very powerful. Most people just redirect the home page but no, that’s just a tiny portion of the value of a domain. Instead, redirect ALL pages to a domain.
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^yourolddomain\.com$ [NC]
RewriteRule ^(.*)$ https://yournewdomain.com [R=301,L]And here it is with the “www” subdomain included:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.yourolddomain\.com$ [NC]
RewriteRule ^(.*)$ https://www.yournewdomain.com [R=301,L]📄 Download a PDF of This Article
