Using .htaccess to Permanently 301 Redirect Old Domain to New Domain

If you haven’t made any changes to your site’s structure but are just transferring it, using the following code in your .htaccess file at the root of your old domain will not only redirect your users, it will also update Google’s index and pass along all your SEO Ranking. The code above is simple regular expression so you can do all kinds of nifty things with it. For example, if you want to redirect subdomains in addition to the root domain, you would use this code: You can also do things like redirect an old subdomain to a directory on the new domain (or vice versa). I did this when I redirected www.groovypost.com/forum/ to forum.groovypost.com. This last example shows you to perform one-off redirects for individual pages. This could be handy if you kept the overall site structure the same (using one of the redirects above) however you want to change a few URLs to the new domain. Just use the following: Being regular expression code, the possibilities are endless. A key takeaway, however, be extremely careful when making these changes to your .htaccess file. Messing with this file can break your Apache webserver and take down your site. So test, test and test again before making any changes. Need help? Drop a comment here or on our free support forum. isn’t your first example code the same as the second one? RewriteEngine On RewriteCond %{HTTP_HOST} ^olddomain.com$ [NC,OR] RewriteCond %{HTTP_HOST} ^www.olddomain.com$ [NC] RewriteRule (.)$ http://newdomain.com/$1 [R=301,L] Redirect 301 /oldpage1.html http://www.newdomain.com/newpage1.html Redirect 301 /oldpage2.html http://www.newdomain.com/newpage2.html Redirect 301 /oldpage3.html http://www.newdomain.com/newpage3.html In fact, over time you will likely add additional REDIRECT 301 code in your .htaccess files throughout the life of your domain. Just keep adding them as you’ve done above. On my site here at groovyPost, I have several hundred from where I moved pages to new URL’s etc… Let me know if you need more help! -S RewriteEngine On RewriteCond %{HTTP_HOST} ^francishome.com$ [NC,OR] RewriteCond %{HTTP_HOST} ^www.francishome.com$ [NC] RewriteRule (.)$ https://www.francishome.ca/$1 [R=301,L] Comment Name * Email *

Δ  Save my name and email and send me emails as new comments are made to this post.

How to Redirect an Old Domain to New Domain via htaccess 301 - 94How to Redirect an Old Domain to New Domain via htaccess 301 - 84