Forum Moderators: phranque
RewriteEngine On
RewriteCond %{HTTP_HOST} ^oldname\.com$ [NC]
RewriteRule ^.*$ [newname.com%{REQUEST_URI}...] [R=301,L]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.oldname\.com$ [NC]
RewriteRule ^.*$ [newname.com%{REQUEST_URI}...] [R=301,L]
What I'm concerned about is that, while the above htaccess code changes the old name to the new name properly, and ends up at the desired page(s), the http code for the redirected requests in CPanel is "200", not "301". My question is, will this continue to cause the same problem, with Google thinking we have two domain names for a single site?
I don't trust cPanel. Try checking your old URL with the WebmasterWorld server headers checker [webmasterworld.com].
You need a straight 301-Moved Permanently response to requests for your old domain to avoid problems.
One way to do this is to point the domain name straight to your server IP address (and to your Web root directory) using your DNS zone file, and then use your redirect code there. There is no need to use a subdirectory or any "pointing" or "forwarding" mechanism that might involve a 200-OK response.
You can also "compress" your code and simplify it:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?oldname\.com [NC]
RewriteRule (.*) http://www.newname.com/$1 [R=301,L]
Avoid end-anchoring the domain name pattern. An appended port number (e.g www.example.com:80) can cause your condition to fail.
Also note that only one RewriteEngine on directive is needed in your code, unless you also use RewriteEngine off to toggle it on and off.
Jim
Some user-agents and caching proxies may append a port number to your domain name. It is perfectly-legal to do so. If this happens, your redirects will fail. Therefore, if a port number is appended, you could appear to have duplicate content.
It can sometimes be quite interesting to try this yourself, by appending port 80 (the standard Web-server port) to the domains in the URLs you request. In some cases, it can act as a cloak-buster, and in other cases, it's more like a site-buster. Well-designed sites should handle it gracefully. Try [google.com:80...] for example.
I believe in robust coding. It minimizes problems in the future. But of course, I'm not aware of what it might take for you to change the file on your server -- there may be some daunting "office politics" in the way, for example. But I recommend you change at least that one aspect of the code, for technical reasons.
If someone is objecting on the basis that an un-anchored HOST pattern is ambiguous, the full solution is to use this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?oldname\.co[b]m(:[0-9]{1,5})?$[/b] [NC]
RewriteRule (.*) http://www.newname.com/$1 [R=301,L]