Picnic Website Code Tutorials

301 Permanent Redirect Old Domain To New Domain

3/10/2013

When changing domains you should 301 redirect your old domain to the new domain. If you haven't made any file name or folder changes during the switch then it's a very easy move. However, if you make a significant amount of changes to the folder structure in the new domain it can quickly turn into a large headache when making the move. You then have two options. One you either write a seperate rule redirecting each old location to the new one. Or Two, you do a blanket 301 redirecting all files in the old domain to the root of the new domain. This is considered bad practice. But if you have no choice because of the difficulty of option one, then it is still the lesser of two evils. The greater evil being having no redirect at all in place. Google will still acknowledge the move. But your visitors to the old domain will have a less than optimal redirect. Below I nailed down the four easiest ways to accomplish either direction you take. Once you get the correct code it really is very easy. Put one of these (or more depending situation) in the htaccess of your old domain to redirect old to new...

// redirect all files from old domain to root of new domain
RewriteRule .* http://www.newdomain.com/ [R=301,L] 
		
// redirect all files from old domain to root of new domain and strip off url variables
RewriteRule .* http://www.newdomain.com/? [R=301,L] 
		
// 1:1 redirect - all old domain files will be redirected to new domain file locations
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L] 
		
redirect old domain file to new domain file location
redirect 301 /old-file-location.html http://www.newdomain.com/new-file-location.html
		

Sponsors

Top Donators

Friends of Mine