Forum Moderators: phranque

Message Too Old, No Replies

301 Redirects to Separate Domains

         

ambaxter

1:39 am on Jun 17, 2009 (gmt 0)

10+ Year Member



I have a site with a new domain. ALL of the content of the site will go to domainA, while content from a single directory will be a directory of the same name on domainB?

jdMorgan

1:34 pm on Jun 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If both domains resolve to the same filespace on the server, this is fairly trivial.

But it's not clear what your set-up is, or whether you want to redirect requests for an old domain to a the new domain, and whether it is domainA or domainB that is the new domain.

Please describe your requirements in detail, and post the code you've tried so far.

Jim

ambaxter

5:23 pm on Jun 17, 2009 (gmt 0)

10+ Year Member



The two are not going to be on the same domain. We have one site that we will no be using (domainX).

The content has been migrated to TWO separate domains. All of the content will now be going to domainA *except* for a single folder, which will be going to domainB. And we named that single folder (on domainB) the same name that it had on domainX.

We have this working (see below) but it overrides any attempt we have to send that other directory to domainB. And grabs ALL of the traffic for domainA.

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{HTTP_HOST} ^(domainX¦www.domainX) [NC]
RewriteRule ^(.*)$ [domainA.com...] [R=301,L]

g1smd

12:31 am on Jun 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The .* pattern means "all" so for the one folder that redirects elsewhere, you'll need to test the folder name that was requested, and place that redirect ahead of this existing one.

There are other code tidy-ups that can be done, but let's do things one step at a time here.

jdMorgan

1:02 am on Jun 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In DomainX/.htaccess:

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

If only DomainX is hosted in this account then the first RewriteCond of each rule is not needed.

Jim

[edited by: jdMorgan at 1:06 am (utc) on June 18, 2009]