When you set the option "Use active domain" on a node with Domain Source submodule, the request get a redirect (302) to an empty domain.

Ex:

1) You set "Use active domain" option as source domain in node id 123
2) You open the following URL in your browser http://subdomain.mydomain.com/node/123

Observed behavior:

You get a 302 redirection to http:///node/123

Expected behavior:

Stay on current domain so stay on http://subdomain.mydomain.com/node/123

The cause of the issue:

domain_source_domain_source_alter() in domain_source.domain.inc does a domain_lookup($source_id) with $source_id = -5 (DOMAIN_SOURCE_USE_ACTIVE constant value):

// The source_id always returns a valid domain.
$source = domain_lookup($source_id);

But domain_lookup returns -1 because it does:
if ((is_null($domain_id) && is_null($subdomain)) || ($domain_id < 0) {
$domains[$key] = -1;
}

While domain_source_domain_source_alter() expects it to return -5 in that case as after the domain_lookup it does:

// DOMAIN_SOURCE_USE_ACTIVE is the status for 'Use active domain.'
if ($source == DOMAIN_SOURCE_USE_ACTIVE) {
$source = domain_get_domain();
}

Comments

bpresles’s picture

Proposed patch attached

bpresles’s picture

Status: Active » Needs review
bpresles’s picture

After further investigation, it seems to be caused by commit 891b5f88517f2a0602438b276cea8a90fa3bc56c related to issue #1864922 (http://drupal.org/node/1864922)

Attached a simpler patch

agentrickard’s picture

Status: Needs review » Postponed (maintainer needs more info)

I don't think "redirect" is the proper term here. Domain Source doesn't issue redirects; it rewrites URLs.

Please clarify. Are you using some other module that issues the redirect?

agentrickard’s picture

Status: Postponed (maintainer needs more info) » Needs work

I agree, however. That logic is not right. This seems more accurate:

/**
 * Implements hook_domain_source_alter().
 */
function domain_source_domain_source_alter(&$source, $nid) {
  $source_id = domain_source_lookup($nid);
  // If FALSE returned, no source is defined.
  if (!$source_id) {
    return;
  }
  // DOMAIN_SOURCE_USE_ACTIVE is the status for 'Use active domain.'
  if ($source_id == DOMAIN_SOURCE_USE_ACTIVE) {
    $source = domain_get_domain();
  }
  // The source_id always returns a valid domain.
  else {
    $source = domain_lookup($source_id);
  }

This needs a proper test.

agentrickard’s picture

Status: Needs work » Needs review
StatusFileSize
new2.54 KB

Here's a patch, but the current tests don't fail like I would like if the new logic is reverted.

bpresles’s picture

Indeed, redirecting is the wrong word, it's indeed just rewriting.

agentrickard’s picture

Title: Redirecting to http:/// (no domain) when using Domain Source "Use active domain" option » Rewriting to http:/// (no domain) when using Domain Source "Use active domain" option

Does the patch fix it?

agentrickard’s picture

Status: Needs review » Fixed

Committed.

   8c004df..4b16060  7.x-3.x -> 7.x-3.x
bpresles’s picture

Yes the patch fix it. Thanks. (and sorry for the delay)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.