Switching my website to a new domain Rewrite rule and 301 Redirects

Here is what i want to do.

I have two domains.

#1. www.old-domain.com
#2. www.new-domain.com

The old domains has been running for sometime and now i want to move the old website to a new domain name. I want to remove the old domain completely from my server so i only have one website running to not waste space. Under the new domain I want it so if someone enters in the old-domain.com domain no matter what page they try to go to it forces them to the new-domain.com.

My sites are all hosted at rackspace.

I’m thinking i would need to do some combination of .htaccess magic with rewrite rules and also maybe something at my registar as well on the old domain to point it to the new-domain.com ip address or something. I host my sites with Rackspace and register my domains with Godaddy.

Anyone know what the Rewrite Rule may look like?

RGD,

You cannot access another domain’s request so doing this from the new site is physically impossible … unless they share the same DocumentRoot on the server. If that’s the case, simply check whether the old domain was requested and then redirect:

RewriteEngine on
RewriteCond %{HTTP_HOST} old-domain [NC]
RewriteRule .? http://www.new-domain.com%{REQUEST_URI} [L,R=301]

You’ll have to keep the old domain for a while but, after a few months, you can let it lapse (or do something else with it).

Regards,

DK

oh right, yeah that makes sense. I suppose i was thinking I could redirect the old domain to the new domain, but then if they went to internal pages they wouldnt get redirected.

Here’s what I’m going to do.

Going to leave old-domain.com hosted on my server for about 3 months. From that domain I want to add a rule in the htaccess file that will redirect to the new-domain. But i also need a rule to handle the redirection if the user enters via a subpage, subsection and I’ll want it to redirect to the same page on the new domain.

So, for example, visiting old-domain.com/subpage2/somepage/ would redirect to new-domain.com/subpage2/somepage/ == essentially the same page but on the new domain. And of course, we also want to redirect all traffic from the homepage to the new-domain.com homepage.

Will the rule you sent me there handle all of that too?

actually, i found my answer. Actually pretty simple. I’m keeping the old domain active and then when people go to that site they will get redirected to the new domain and also if they need to get to the page too, all of that works. Simple one line rule.

alias redirect

Redirect 301 / http://www.newdomain.com/

RGD,

Yes. The {REQUEST_URI} variable would remain unchanged.

BEST solution! Keep the old domain on its website (separate from the new domain) and use the mod_alias redirection … as you have done. :tup:

Note: Your original question implied that you wanted to use the .htaccess ON THE NEW SERVER to perform the redirection. I stand by my response that, in using the .htaccess on the new domain, they must be co-located. As you’ve found, even better to keep the old domain active on the old server and use mod_alias to perform the redirection. When it dies (in three months), the new domain will be “clean” (no changes to the .htaccess required).

Regards,

DK