Forum Moderators: phranque

Message Too Old, No Replies

redirect mysite.com/anypage to mysite.org/anypage

aliased domains redirect?

         

allegory

2:59 pm on Nov 8, 2003 (gmt 0)

10+ Year Member



I currently have a site that is accessible through both mysite.com and mysite.org, but I want all requests for mysite.com/anypage to redirect to mysite.org/anypage.

I thought this might do it, but it doesn't:

RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com
RewriteRule ^/(.+) [mysite.org...] [R,L]

What am I doing wrong?

jdMorgan

3:45 pm on Nov 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



allegory,

Welcome to WebmasterWorld [webmasterworld.com]!

That code should work (almost right) *if* you put it in httpd.conf. For use in .htaccess, try:


RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteRule ^(.*) http://www.example.org/$1 [R=301,L]

(The leading slash is stripped off the requested URI tested by RewriteRule in an .htaccess context. Also, use a 301 redirect to avoid potentially serious problems with loss of rankings search engines.)

If you want to redirect *ALL* hostnames that are *not* exactly equal to "www.example.org", try this variant:


RewriteCond %{HTTP_HOST} !^www\.example\.org
RewriteRule ^(.*) http://www.example.org/$1 [R=301,L]

This will "correct" any URL that is not exactly an all-lowercase www.example.org. This construct can be used to simplify all the other RewriteRules and other hostname tests in scripts, etc., by ensuring that only one version of your hostname will be used to access your site.

Ref: Introduction to mod_rewrite [webmasterworld.com]

Jim

allegory

6:40 pm on Nov 8, 2003 (gmt 0)

10+ Year Member



thanks! that worked.

allegory

7:02 pm on Nov 8, 2003 (gmt 0)

10+ Year Member



mysite.com has a high pagerank in google and mysite.org doesn't, because a lot of other sites link to mysite.com.

will the 301 cause google switch the good pagerank over to mysite.org?

jdMorgan

11:06 pm on Nov 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, usually. Hopefully. I think so. No one can promise.

Generally yes, but you want to get as many of those "incorrect" incoming links corrected as you can, over time.

Jim