301 Redirect question

I have a client who needed to start using a new domain name and wanted 301’s to preserve link equity. When I tried to rename the site and update links, the 301’s ended up in an infinite loop. So I duplicated his wordpress site and installed on new domain and left old site the way it was. Then the redirects worked fine.

My question is, can the redirects for the OLD site be written on the NEW site so I dont have to keep the old site on the server anymore?

So what you’re asking is
“If someone comes to my new address while looking for my old address, can I send them to my new address” ??

s83,

Yes, either use a RewriteMap (if you have access to the server or vhosts conf file) or a 404 handler which can do a lookup of a database table to provide a redirection.

On the other hand, your loopy code might be fixed to eliminate the loop. I’ll bet your using the :kaioken: EVERYTHING :kaioken: (or NOTHING) atom in your regex, aren’t you?

Take the hard (and slower) way (option #1) or the easy (and fast) way (option #2) but you’ll need to show the loopy code you used.

Regards,

DK

Absolutely. Most likely you’ll need to use a RewriteCond that checks the HTTP_HOST value so that the redirect happens only when the request is for the old host name.

This is what is on the old site, when I tried on new site I got the loop. I know they just dont want any links to the old site to be dead…

Permanent URL redirect

Redirect 301 / http://www.hoffmanhousebuyers.com/
Redirect 301 /companies-that-buy-houses/ http://www.hoffmanhousebuyers.com/companies-that-buy-houses/
Redirect 301 /home/how-to-stop-foreclosures-in-philadelphia-p/ http://www.hoffmanhousebuyers.com/home/how-to-stop-foreclosures-in-philadelphia-p/
Redirect 301 /sell-my-house-fast/ http://www.hoffmanhousebuyers.com/sell-my-house-fast/
Redirect 301 /how-to-sell-your-house-fast/ http://www.hoffmanhousebuyers.com/how-to-sell-your-house-fast/
Redirect 301 /contact/ http://www.hoffmanhousebuyers.com/contact/

The problem is that you’re redirecting indiscriminately, regardless if the request came from your old host or you new host. So your new host ends up redirecting to itself, which then redirects to itself, and so on. You’ll need to check the HTTP_HOST value so that the redirect happens only when the request is from the old host.

Apache 2.4+ added an <If> directive, but I’m not sure yet how widespread 2.4 is over 2.2, so to be safe and stay compatible with 2.2, we’ll have to change your redirects into rewrite rules so that we can use rewrite conditions.

RewriteEngine On

# If this request came from the old host,
# then redirect all URLs to the same URL on the new host
RewriteCond %{HTTP_HOST} =www.oldsite.com
RewriteRule ^(.*)$ http://www.newsite.com/$1 [R=301,L]