Forum Moderators: phranque

Message Too Old, No Replies

Another 301 redirect question

         

georgec

8:28 pm on Jan 28, 2005 (gmt 0)

10+ Year Member



Hi:
My site currently has two domains pointing to it (with no redirection) due to the fact that I changed domains a few years ago, and still have sites linking to it using the old domain. The problem is, Google frequently switches between the two domains when indexing. Now the familar question- what should I put in a .htaccess file to do a 301 redirect to the exact same page on the current domain when the old is typed? I've tried the code:

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.olddomain\.com [NC]
RewriteRule ^(.*)$ [newdomain.com...] [R=301,L]

though a couple of problems:

1) If "www" is not typed, I don't get the redirection (ie: [olddomain.com...]

2) Even if I type the old domain corrrectly (ie: (http://www.olddomain.com/apage.com), all I get now is actually a redirect to a 404 page not found error.

Any help would be great. Thanks,

jdMorgan

8:43 pm on Jan 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To fix your "missing www" problem, just make the www. optional in the RewriteCond:

RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com [NC]

I don't know why your "correctly-requested" page is going 404 -- The RewriteRule looks OK. You might want to take a look at your server error log to see where it redirected to. There may be some problem in httpd.conf or in your "control panel" that is causing this.

Jim

georgec

10:44 pm on Jan 29, 2005 (gmt 0)

10+ Year Member



Hi jdMorgan:
Thanks for the help. No idea why my server redirects to a 404 error instead. I guess it's something specific to my server, though I know mod_rewrite does work on it, since I use it to disable hotlinking on my site. Hmmm...

jdMorgan

12:27 am on Jan 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



take a look at your server error log

Jim