What do you think is the best way to 301 redirect my entire domain?

I developed a new site to display my demos. I could simply htaccess 301 my entire site. But then every visitor would be confused they didn’t land on their expected page. But that’s best for google. I could meta refresh after 5 seconds and say the site has moved, so good for visitors, but meta is bad for seo. I could php 301 it using the same ideas.

Is there any other way I’m not thinking of? If you switched domain names, and you spent the last 6 years building seo for your old domain, how would you 301 redirect to your new domain? Remembering that I also want to inform visitors that I changed locations.

Thanks, Eric W

Whether your domain page has same category or not…In case,it would be same category users can easily identify their expected page, once you redirect the domain page to new page…

wow so I must be the first one to do this. I guess no body can offer their experience with this then.

I believe something like this in your htaccess would suffice.

<If "%{HTTP_HOST} != 'olddoamin.com'">
	Redirect permanent / http://newdomain.com/
</If>

Actually, Goolgle webmasters offers such information:

It also explains how to avoid 404 erros. I am assuming that is what worries you.

Thank you! What exactly does that code say and do? Thanks

Good link. Thank you

Well first, oops, I may have mis-copied it (found it on Apache’s website). It is supposed to check what domain is being accessed, and redirect to another.

<If "%{HTTP_HOST} != 'newdomain.com'">
	Redirect permanent / http://newdomain.com/
</If>

So if the domain being access is not newdomain.com, perform a permanent redirect to newdomain.com

You could 301 redirect visitors to the new domain, and on the new domain check the referrer for the old domain name and if the old domain name is found in the referrer, display a notice letting the visitor know what’s going on.

Hi,

A way other than @cpradio’s is to use the following mod_rewrite:

// With www



# Redirect old_domain.com to new_domain.com with 301
RewriteCond %{HTTP_HOST} !^www\\.new_domain\\.com
RewriteCond %{HTTP_HOST} !^$
RewriteRule .? http://www.new_domain.com%{REQUEST_URI} [R=301,L]

// Without www


RewriteCond %{HTTP_HOST} !^new_domain\\.com
RewriteCond %{HTTP_HOST} !^$
RewriteRule .? http://new_domain.com%{REQUEST_URI} [R=301,L]

This way for any page that existed on the old site as long as the same page names or index plus parameters will be redirected to the same page name on the new site. The seo bots will learn the 301 and your juice won’t be lost.

What about this redirect? Is it missing anything that the above examples have?

Redirect 301 / http://newdomain.com/

If both domains point to the same location, you would likely introduce an infinite loop, as it is redirecting all requests to newdomain.com and if newdomain.com resolves to the same location as olddomain.com it will still enforce that redirection as it doesn’t specify the request had to be made from a specific host.

I dont know. JdMorgan with 25,000 posts says to use that above one liner. http://www.webmasterworld.com/apache/3242480.htm. Sorry - not being argumentative - just trying to find the best way to do this.

OH WAIT! My bad. I miss spoke. I just realized. This is probably going to make it easy. They are not going to match from old to new - not 1:1. They are going to be olddomain.file.php and newdomain/folder/file.php. And the folder changes depending on the file group. So in that case what would be the best way? I have 800+ pages. So it’s probably impracticable to redirect each seperatly. So should I just redirect the entire old domain to the new domain root?

Can you give us more examples of the redirections you need? If there is a pattern, it wouldn’t be terribly difficult to get the redirection to handle all 800 pages.

For example:
olddomain/file.php newdomain/folder/file.php (need to know how folder would be defined, hard coded?)
olddomain/folder-file.php newdomain/folder/file.php (grab folder from filename)
etc.

Without know what you have and where you want it to go, then the only recommendation I have is to redirect all traffic to the root of the new domain (although it would be best to redirect to the new page location).

Good morning,

I think it’s going to be easiest to just redirect to the root but you tell me. I don’t beleive there is going to be a pattern. I have 800+ css, php, htaccess, js, photoshop, etc demos and such. In the old domain they were all just in olddomain/code/demo.php. Now in the new domain I am going to group them into there corresponding folder. So css demos will go in newdomain/code/css/demo.php. PHP demos in newdomain/code/php/demo.php and so on. There will be about 17 newly named folders/groups that the files will be going into. Thanks!

Ah, you are probably right, it might not be easy to redirect all of those. I’d personally go the blanket redirection route at this point in time, if you weren’t worried about losing your search results. If you want the search result to remain valid, you’ll have to write conditions for each page unfortunately (or so it seems)…

Ok thanks. So what the best htaccess code for a blanket redirection to the new domain root?

Are the two domains pointing to two different websites (possibly two separate servers)?

If so, you can use your blanket one of

Redirect 301 / http://newdomain.com/

If the two domains point to the same website folder (so you have the old file and the new files inter-mixed), then you need to use

<If "%{HTTP_HOST} != 'newdomain.com'">
	Redirect permanent / http://newdomain.com/
</If>

Hmmm. What am I then? It’s on the same server. But a different folder I believe. Meaning I will delete the olddomain addson and add the new domain addon. So the host/server “should” view it as a new folder right?

The host set up is… The main domain sits in public_html/ and the addon domain (the new and old domains) site at public_html/addondomain. Let me know if that’s not clear. Thanks a lot for the continued help!

Additionally they are not sub domains. But full fledge domains.