.htaccess Code for 301 Redirecting an Old Domain to a New Domain

If you just purchased a new domain and want to swap it out on an apache server you can leave your files where they are. Just create a new DNS zone on your server and then add this code below to your .htaccess file:

RewriteCond %{HTTP_HOST} ^www.olddomain.com [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/%241 [L,R=301]

This depends upon your server configuration and settings and may not always work. But when it does work, its by far the best solution for a large site.

No comments yet. Be the first



Leave a Comment

You must be logged in to post a comment.