How to redirect links to a single domain in a multi-domain setup? I am working on a project that uses Domain Access. The site has two domains one public(example.com) &amp; one for members(example.com/members).

Some contents are common to both domains and some are domain specific.

Any link rendered on webpages has a relative path to that domain. 

eg. A page that is displayed on both sites has the link (/some/link). Clicking it would take you to example.com/some/link if you click it on example.com AND to example.com/members/some/link if you click it on example.com/members

There are a few links that I want to appear on both domains but they should redirect to the members domain only.

eg. for the case described above the link should redirect to example.com/members/some/link even if it is clicked form the example.com domain.

Is there a way to do it?

UPDATE:

These are subdomains example.com &amp; members.example.com. There is some server-side settings for url rewrite that makes them appear as example.com &amp; example.com/members in URL.
There is a special module for that: https://www.drupal.org/project/domain_path_rewrite.

The idea is to automatically rewrite the relative links to the absolute ones so they always point to the proper domain. Something like:

/**
 * Implements hook_url_outbound_alter().
 */
function domain_path_rewrite_url_outbound_alter(&amp;$path, &amp;$options, $original_path) {
  if ($domain_path = _domain_path_rewrite_domain_path($original_path)) {
    $path = $domain_path['url'];
    $options['external'] = strpos($path, '//') !== FALSE;
  }
}


Of course, is's only possible if you're printing the links programmatically. Otherwise nobody knows to which domain the links belong to and most likely you need custom rewrite rule.