Forum Moderators: phranque

Message Too Old, No Replies

301 redirect returning 200 code?

trying to avoid Google penalty

         

RoySpencer

8:41 pm on Oct 5, 2004 (gmt 0)

10+ Year Member



A few months ago, we changed to a new domain name, but had the old name forwarded to the site also. Our Google rankings dropped out of sight after a few months, and the index page disappearing completely from google's index. We are now trying to use the 301 redirect approach, with the old name pointed to a subdomain, and an htaccess file in that subdomain with the following:

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?

jdMorgan

12:21 am on Oct 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> the http code for the redirected requests in CPanel is "200", not "301"

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

RoySpencer

11:27 am on Oct 6, 2004 (gmt 0)

10+ Year Member



Thanks, Jim:
The checker responded with a 301, so I assume we're OK even if we leave it as sloppy as it is(?)
-Roy

jdMorgan

1:01 pm on Oct 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> An appended port number (e.g www.example.com:80) can cause your condition to fail.

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]

Jim

RoySpencer

2:53 pm on Oct 6, 2004 (gmt 0)

10+ Year Member



Jim:
It also worked with port 80 appended, but we went ahead and implemented your last suggestion, and we made sure it also works in the header checker (it did).
Thanks again!
-Roy