I have a site hosted at Network Solutions, along with two domains. “OldDomain” used to point to hosting account, but now “NewDomain” points to host.
PROBLEM: Redirecting “OldDomain” doesn’t work without creating redirect loops.
I’ve tried the following:
1) Redirecting OldDomain (with/out “www”), plus redirect non-www for NewDomain:
RewriteCond %{HTTP_HOST} ^www.olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^olddomain.com$
RewriteCond %{HTTP_HOST} ^newdomain.com [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,NC]
2) Redirect using PHP header:
$dom = $_SERVER['HTTP_HOST'];
if(strripos($dom, 'olddomain.com') >= 0) {
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.newdomain.com/");
}
Option #1 doesn’t do anything. Option #2 puts me in a redirect loop even with the first two RewriteCond rules commented out.
I’ve done many .htaccess redirects before, but this one is giving me a headache as to why it’s not acting right. Is this just a Network Solutions issue? I’ve never had problems with any other hosts. By the way, NS support tells me I have to pay to forward OldDomain to NewDomain because it’s currently not pointing to a hosting package. If that’s the case, why can’t I point both domains to the same hosting package and at least use the PHP redirect in the header of the index page??
THANKS for any help on this!
Option 1 doesn’t do anything because you have this logic in your conditions
www.olddomain.comolddomain.comnewdomain.comObviously, the host can’t both be
newdomain.comand either one of the old domains. Try adding an additional[OR]to that and some[NC], too:Option 2, you have this to see if the host contains
olddomain.com:Problem here is
strripos()returns FALSE (which is also a 0) if string isn’t found, which means if$domwaswww.newdomain.com, it would return FALSE, or0, and the>= 0would be true, thus redirecting again. You need to do something like this: