If a user visits a page that Domain Access blocks for them, they get a permissions issue. I would like instead to attempt to redirect them to a subdomain in which they DO have access to that node.

This desire springs from the links that are included in the alert emails for OG. Right now they point to the root domain, and a lot of members don't have sufficient rights to view them there, only on the subdomains the posts were published to. I thought about fixing it in OG directly, but I'm hoping this approach would cut off other potential problems down the line.

My suspicion is that creating a custom 403 page with a little php code that searches all the available domains and eventually does a domain_goto would do the trick. I'm already working on this, but I thought someone else might have already done it and be willing to share. If I figure it out I'll post it back here.

Comments

gcassie’s picture

It would also help solve the problem of URLs in RSS feeds being directed only at the root site.

agentrickard’s picture

Using Domain Source or turning on SEO should solve this problem by forcing all links to write to the proper domain, but you would need to upgrade to 5.x.1.4 as well.

You can also "fix" the feed issue by putting the following into 'Special page requests'

*/feed

Doing so will cause DA to ignore its access rules when that path loads and write the URLs to the proper destination domain.

gcassie’s picture

Status: Active » Closed (fixed)

First test seem to show that upgrading to 5.x-1.4 fixed the links in the feeds and OG emails, which was great. Thank you for that suggestion.

I should mention that upgrading from 5.x.-1.1 to 5.x-1.4 replaced all the entries in the domain_access table with default values. I was able to restore them from a backup.

gcassie’s picture

Status: Closed (fixed) » Needs review

I still had people hitting pages from the wrong domain for whatever reason. I've added a bit of code to my custom 403 page. If the user is trying to just view a node that is only published to a single domain and they just happen to be on the wrong domain, this will bounce them to a domain where they can view it.

global $user;
global $_domain;
$path = urldecode(str_replace('destination=', '', drupal_get_destination()));
$path_bits = explode("/", $path);
if ($path_bits[0] == 'node' && is_numeric($path_bits[1]) && !$path_bits[2]) {
  $result = db_query("SELECT * FROM {node_access} na WHERE nid = %d AND realm = 'domain_id' AND grant_view = 1", $path_bits[1]);
  $domain_grants = array();
  while ($domain_grant = db_fetch_array($result)) {
    $domain_grants[] = $domain_grant;
  }
  if (count($domain_grants) === 1 && $domain_grants[0]['gid'] != $_domain['domain_id']){
    $good_domain = domain_lookup($domain_grants[0]['gid']);
    drupal_goto($good_domain['path'] . $path_bits[0] .'/'. $path_bits[1]);
  }
}
agentrickard’s picture

Version: 5.x-1.1 » 5.x-1.6

I think that #255711: Redirect search engines may be related to this. So one of these is a duplicate.

gcassie’s picture

From what I can see there, that module deals with spiders. Which is very useful, but most of my wrong domain issues come from writers and editors not linking to the proper domain within content they've created. I think 255711 would bypass that because the user agent is not a spider.

agentrickard’s picture

I think 5.x.1.6 solves this issue. If a server request for a non-existent domain is received, we pop the user to the primary domain and post a message.

See #293453: Wildcard DNS - default domain

Ibn al-Hazardous’s picture

The module in "redirect search engines" (255711) has on option in the domain advanced settings, so you can redirect all visitors.

I suppose the problem with using it for ordinary users is that the user doesn't get a heads up - but is quietly sent a redirect http header. So if you want to give the user a "change your bookmarks" message - maybe some php and javascript (to get a timed out redirect) in your 403 is a better solution? Depends on what you want to do.

agentrickard’s picture

Status: Needs review » Postponed

Like #255711: Redirect search engines, I do not intedn to commit this.

freestyler’s picture

I also have custom error + domain access

I tried gcasie's code and at first it didnt worked (im on drupal 6)

To make it work I had to change the === for >= in the following line:

if (count($domain_grants) === 1 && $domain_grants[0]['gid'] != $_domain['domain_id']){

now I get a redirect error (an infinite loop) caused by drupal_goto, on this line:

drupal_goto($good_domain['path'] . $path_bits[0] .'/'. $path_bits[1]);

Arguments are ok as I printed them on screen and I even managed to redirect via javascript.

Can anyone help me solve the drupal_goto infinite redirect?

agentrickard’s picture

Status: Postponed » Closed (won't fix)