Marston Gould
Marston Gould

Reputation: 85

Redirect based on referring url Query string

I have two large websites, both with millions of sessions of traffic.

The first domain, call it domainA.com purchased a portion of domainB.com, but not the entire domain. Domain A purchased everything within a subfolder, call it /us/

About 90% of the traffic to domainB.com goes to a small number of overall pages - around 5k.

I need to set up a redirect between the two domains at a granular level to maintain customer experience.

I have mapped the specific pages of the 5k pages from domainB to domainA. What I'm thinking of doing is setting up a direct in the htaccess file that essentially has logic as follow:

If URL request includes domainB.com/us/ -> domainA.com/domainB?url=domainB.com/us/foo

Then when the redirect is sent to a page domainA/.com/domainB the url parameter can be read, a script can check it against the table and redirect it to the appropriate page on domainA.

The benefit here is that the company DomainB can have a pretty small redirect code on their htaccess file and most of the redirection is actually captured and controlled by CompanyA. Does this make sense?

Upvotes: 0

Views: 74

Answers (1)

anubhava
anubhava

Reputation: 785276

You can use this rule in root .htaccess of domainB:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(domainB)\.com$ [NC]
RewriteRule ^ http://domainA.com/%1?url=%{HTTP_HOST}%{REQUEST_URI}/foo [L,QSA,NE,R=302]

Upvotes: 1

Related Questions