Redirect an Old Domain to a New Domain with .htaccess

If you have decided to change your site’s domain and are hosting your old site on an Apache server, then redirecting traffic to the new site is relatively simple. The most important aspect of the move is to ensure that you don’t lose visitors and that you don’t lose any existing rankings with the search engines. A 301 redirect, or permanent redirect, will ensure that both human visitors and search engines alike are automatically and seamlessly pointed to the new domain.

Below is the code that you should place in your .htaccess file on the old site:

Obviously, you will need to replace the instances of olddomain and newdomain with your actual domain names and if your site isn’t a .com site, then that will need to change as well.

One thing to keep in mind when moving to a new domain is that the rule above will take a visitor to the equivalent URL on the new domain. In other words, if a user goes to, then they will be redirected to But what happens if you actually moved that page to when you made the move to the new domain? Then you will have to add additional redirects to your .htaccess file to ensure that visitors are directed to the appropriate pages for these altered locations. Because of this, it is highly recommended that you don’t try to restructure your site at the same time that you make the move from one domain to another. One reason that this is a bad idea is because if something goes horribly wrong with your SEO, you won’t know whether it was because of the domain change or because of the site restructure.

Oh, and please be aware that your browser caches 301 redirects, so it is best to start with a 302 redirect when testing.

2 thoughts on “Redirect an Old Domain to a New Domain with .htaccess”

    1. If you use the code as-is in this article, you would NOT be able to access the admin of the old site. However, it is possible to add an exception to the redirect rule listed here by adding this line after the RewriteEngine On directive:

      RewriteCond %{REQUEST_URI} !^/?wp-.*

      This will ensure that anything starting with /wp- after the domain will not be redirected. This includes anything in the wp-admin directory as well as wp-login.php so you should be able to access the WordPress admin and login page. Just be aware that you may need to clear your browser cache since 301 redirects are cached.

Leave a Reply

Your email address will not be published. Required fields are marked *