1

I am working on a project that uses Domain Access. The site has two domains one public(example.com) & 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 & members.example.com. There is some server-side settings for url rewrite that makes them appear as example.com & example.com/members in URL.

  • I would not call those "domains", they are folders. How did you implement Domain Access applied to folders? – ermannob Jan 23 '14 at 11:15
  • @ermannob: No, they are subdomains. example.com & members.example.com. there is some server-side settings for url rewrite that make them looks so. I will add this in question. – kmdhrm Jan 23 '14 at 11:35
  • If you have a special case for a couple of specific links, why not just use absolute urls for those links? The only way an automated system could know which links to handle in the special way is if you implemented some sort of custom input filter with a syntax that allows you to identify such links. – rooby Jan 27 '14 at 14:25
  • @rooby: That is the issue. I currently have more than 100 such links and there are more to come.... – kmdhrm Jan 27 '14 at 15:19
1

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(&$path, &$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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.