helenbn
helenbn

Reputation: 33

.htaccess to RewriteRule or Redirect from one dynamic url domain to another domain

I have barely any knowledge of .htaccess but I fumble with code. :)

I have one CMS with 2 domain names, each domain pulls a totally different site but managed through one back end. The sites are related so there is no real secrecy - a parent and a child.

I have one extension that must operate on one domain only. It handles payments through PayPal and PayPal restricts accounts to only one domain per organization. It is used with both domains.

I have relative linking throughout the back end so menu and article links to anything that has to do with that extension carry the domain from which it is generated. I need a way to automatically direct anything from the child site for just that extension to the parent site, both messy and SEF links.

So, here is an example:

child.com/index.php?option=com_civicrm&task=civicrm/pcp/info&reset=1&id=1

to go to

parent.org/index.php?option=com_civicrm&task=civicrm/pcp/info&reset=1&id=1

and

child.com/wildcard/wildcard

to go to

parent.org/wildcard/wildcard

The extension is com_civicrm. I need any variables after it to work. These may and may not be ".../pcp/..."

And if this matters, the back end only differs by parent.org/administrator/index.php?option=com_civicrm... so I don't want to accidentally direct the back end to the front end by accidentally losing the "administrator".

Thanks in advance, Helen

Upvotes: 0

Views: 632

Answers (1)

Gerben
Gerben

Reputation: 16825

RewriteEngine On
RewriteBase /

# if domain is child.com, and url is '/wildcard/wildcard', redirect to same url on parent.org
RewriteCond %{HTTP_HOST} child\.com$
RewriteRule ^wildcard/wildcard$ http://parent.org/wildcard/wildcard [R=302,L]

# if domain is child.com, and querystring contains 'option=com_civicrm', redirect to same url on parent.org
RewriteCond %{HTTP_HOST} child\.com$
RewriteCond %{QUERY_STRING} option=com_civicrm
RewriteRule (.*) http://parent.org/$1 [R=302,L]

Happy fumbling :-)

Upvotes: 1

Related Questions