Hi I would like to have an option where DA rewrites all outbound links to other affiliate nodes but not rewriting links to nodes that are published to all affiliates.
To be short and simple, something like SEO but minus rewriting all affiliate links to root domain.

Also it would be nice to have DA checks if url_alias table is prefixed when rewriting links. In case the node has a different alias in other subdomain.

Comments

agentrickard’s picture

StatusFileSize
new13.4 KB
Hi I would like to have an option where DA rewrites all outbound links to other affiliate nodes but not rewriting links to nodes that are published to all affiliates.

This already exists. Look under the Advanced Settings for "Default source domain" -- see attached.

Checking the url_alias for prefixing would be possible, but take a little code trickery. I would like to see a patch for that.

ariflukito’s picture

ah I dont have that option, is that D6 only?

what is the best way to alter path aliasing, as far as I know there is no hook for that.
The only way you can do it is by patching core. Am I correct on this one?

agentrickard’s picture

You must enable Domain Source, even if you do not use it.

[edit: I said "Domain Strict" originally, which is incorrect.

ariflukito’s picture

agentrickard’s picture

What am I supposed to be seeing?

agentrickard’s picture

This feature is in 5.x.1.5 and higher. It does not require Domain Source.

ariflukito’s picture

StatusFileSize
new1.44 KB

sorry I was in hurry yesterday
drupal 5 doesn't have the option "Do not change domain"

D6 -> $options = array('-1' => t('Do not change domain'));
D5 -> $options = array();

edit: attached patch for D5 head

also I edited my comment above after you posted

what is the best way to alter path aliasing, as far as I know there is no hook for that.
The only way you can do it is by patching core. Am I correct on this one?
agentrickard’s picture

Now I see. The patch is appropriate, but you should compare the custom_url_rewrite_outbound() function in both versions as well, since we act based on that setting in that function.

You can (in D5) alter path aliasing by using custom_url_rewrite(). DA includes a patch that backports custom_url_rewrite_outbound() and custom_url_rewrite_inbound() from D6. With some modification to custom_url_rewrite_outbound(), you could do domain-specific path lookups.

You would have to determine the target domain for the link, then switch database tables, and then write the link. It is possible, but I do not have time at the moment.

ariflukito’s picture

yes my patch has already included the change on custom_url_rewrite_outbound()

custom_url_rewrite_outbound() on D5 is called before drupal_get_path_alias() so it is a bit tricky here.

agentrickard’s picture

custom_url_rewrite_outbound() on D5 is called before drupal_get_path_alias() 

The included patch does that? If so, we should rewrite the patch.

ariflukito’s picture

StatusFileSize
new2.15 KB
new1.94 KB

ok here is my first attempt
patch for drupal 5
patched common.inc to have the same execution path as drupal 6 so that the custom_url_rewrite_outbound() is called after drupal_get_path_alias()
the alias lookup codes mostly borrowed from drupal_lookup_path()

agentrickard’s picture

Looks good, just from reading through the code. This will need to go into the 5.x.2 / 6.x.2 release, since it changes the patch that needs to be applied.

Are your tests working as expected?

The only other thing I can think is how to make this optional, so that we only use this routine in certain cases. Maybe we provide a separate include with Domain Prefix so that, if you want this feature, you place a different include file in settings.php.

agentrickard’s picture

Version: 5.x-1.6 » 5.x-1.7
Status: Active » Needs review

Status change!

ariflukito’s picture

it's not perfect yet, I haven't handled certain cases. I roll out a new one later.

ariflukito’s picture

StatusFileSize
new3.18 KB

ok here is the new one
I separate it into new functions
domain_prefix_get_path_alias() and domain_prefix_lookup_path()
they work the same way like drupal except the domain_prefix_lookup_path() only does aliasing.

I have done a little bit of testing and it is working so far with my setup.

ariflukito’s picture

StatusFileSize
new3.66 KB

patch for D6

I've just found one problem unrelated to the patch but semi-related to the issue
If we have different url alias in different domain for the same node, domain switcher and domain nav will not work.
They will give page not found error.

agentrickard’s picture

That makes sense. Take a look at the domain_uri() function, it may need to be extneded with your path logic.

ariflukito’s picture

StatusFileSize
new943 bytes
new943 bytes

ok here is the patch for domain_get_uri() function.

now we just need to decide where to put those new functions, you still want to make it optional?

agentrickard’s picture

I don't know. I am in Budapest after DrupalCON Szeged, and will not get a chance to really think about this until Monday.

agentrickard’s picture

Just took a look. The one part that I don't like is the direct call to domain_prefix_get_path_alias() and the function_exists() that goes with it.

It would be more Drupal if we used a hook here instead.

So I suppose we would need hook_domainpath(), which would let other modules modify the path.

<?php
hook_domainpath($domain_id, $path, $path_language = '') {
 // code here
}
?>

Then we can just invoke the hook without having to use the function_exists() bit in our code. In this case, we do not need a separate settings.php file for Domain Prefix.

agentrickard’s picture

Status: Needs review » Needs work
ariflukito’s picture

I don't think letting multiple modules modify the path is a good idea. I don't see any benefit doing that.

If module A and module B implement hook_domainpath(). Module A alter the $path to $new_path then what would module B do?
or if both module A and module B return different path based on original path, which one would we choose?

note that using hook indirectly call function_exists()
well I know it's a little bit ugly but I don't see using hook is an option.

what do you think?

agentrickard’s picture

Using a hook is how we do things. Look at hook_domainload() or hook_nodeapi().

Will there be cases where modules compete? Possibly, but that can be fixed at the module level. Our task is to build a modular framework that supports extension. Running module-specific functions calls (exceptions, really) goes against that goal.

ariflukito’s picture

StatusFileSize
new5.5 KB
new5.49 KB

Ok here is the new patch

drupal 5 needs new common.inc patch from #11
domain_get_uri() patch is merged into this patch

can you please commit the patch from #7

edit: patch updated with same file name, make sure you don't get the cached one

agentrickard’s picture

Status: Needs work » Needs review

OK, the patch from #7 has been committed to the d5 branch -- it is easy to lose track of multiple patches in an issue.

agentrickard’s picture

Version: 5.x-1.7 » 5.x-1.9

This got confused with another patch. #7 has been committed. #24 still needs review.

ariflukito’s picture

StatusFileSize
new5.53 KB

Updated d5 patch
d6 head looks unstable now.

agentrickard’s picture

D6 HEAD is working. Domain Views is incomplete, but the rest should be fine. See http://drupal.org/node/320388

This should actually apply to D6 pretty cleanly.

agentrickard’s picture

Status: Needs review » Patch (to be ported)
StatusFileSize
new10.24 KB

This has been committed to HEAD (D6). Note that I took the opportunity to optimize the way this code works.

Two special considerations:

-- Any implementation of this hook will now run on _all_ path lookups, not just when DA rewrites the path. This is by design, since there are paths other than node paths that might need to be rewritten.

-- Because of this, the hook could be _very_ resource intensive. So I broke it out into a special file that is only loaded IFF we know that a prefixed {url_alias} table is present. This saves a ton of potential calls to the function that might not be needed.

For details, see domain_prefix_init() and domain_prefix.path.inc.

Updated patch attached for D5 reference -- though the patch is for D6.

ariflukito’s picture

-- Any implementation of this hook will now run on _all_ path lookups, not just when DA rewrites the path. This is by design, since there are paths other than node paths that might need to be rewritten.

Wasn't that already the case before? The hook is only needed to run when DA changes the base_url or else the lookup will be handled by drupal_get_path_alias().

if ($path_rewrite > 0) {
    $path = domain_path($_domain['domain_id'], $original_path, isset($options['language']) ? $options['language']->language : '');
  }

This wouldn't work. The first parameter $_domain['domain_id] causes the lookup on active domain's url_alias table. What we want here is the target domain_id.

In the domain_get_uri(), you added this.

if ($string == $alias) {
  $alias = drupal_get_path_alias($path);
}

What is it for? It doesn't seem to do anything. $string is the aliased $path, so drupal_get_path_alias($path) will give you $string. But $alias is already equal to $string based on the condition. I am confused.

agentrickard’s picture

Version: 5.x-1.9 » 6.x-2.0-rc4

I took that last bit out last night, so check the newest version of HEAD.

The code in custom_url_rewrite.inc is correct. Because of how the Domain Switcher block works, we have to run some checks against the default 'url_alias' table.

And no, custom_url_rewrite.inc is designed to _only_ rewrite node paths -- see the check for if ($nid) near the top. So it would have had no effect if you wanted to change path aliases for a path like 'user,' so we have to run the multi-domain path lookup on _every_ path. The result, if you have multiple domains, is that you might end up running dozens or hundreds of path lookups per page.

The code seems to be as optimized as it can be, though.

Please test before claiming that something doesn't work.

ariflukito’s picture

I'm sorry I should say I have already tested that and it didn't work. The first paramater is telling to do the path lookup on this domain.

The result, if you have multiple domains, is that you might end up running dozens or hundreds of path lookups per page.

I think it doesn't matter on how many domains you have, there is only one lookup per path.

I think you may have a different use case to mine. My use case is I want to have a same alias for 2 different nodes. First node is assigned to domain A and the other to domain B. I want to link both nodes from root domain. So I have something like this:

a.example.com/products -> node/1
b.example.com/products -> node/2

the alias on root domain
example.com/products-a -> node/1
example.com/products-b -> node/2

without the rewrite I get this
a.example.com/products-a and
b.example.com/products-b
and as a result I get page not found error.

edit: this is unrelated I noticed on Node Link Patterns you have this "node\%n\outline". It uses forward slashes instead of back slashes like other patterns.

ariflukito’s picture

StatusFileSize
new676 bytes

performance improvement, avoid calling db_table_exists multiple times

agentrickard’s picture

Yes, you were correct. I had tested it in the Domain Switcher, but not in custom_url_rewrite().

Patches committed to HEAD.

The problem that remains -- which I am not sure how to solve -- is what to do if you have two separate aliases for a path that is not a node. The Domain Switcher handles this through the use of domain_get_uri(). But normal links do not, and I do not see any way to handle that without some very nasty regex code that I don't think we need.

In most cases, this will not be an issue, though I could see problems with menu links that span multiple domains -- unless they are node paths, they will not be aliased correctly. So perhaps just a documentation note about the limitations of this approach.

ariflukito’s picture

StatusFileSize
new2.21 KB

Couple things:

- $domain[$nid]['domain_id'] is not always set, so I introduce a new variable $target_domain_id default to $_domain['domain_id']. And if we use default source, the target would be default source domain id.
- I added check $path != '' because I saw '' and '' (empty string) were being passed around.
- Added drupal_is_front_page() check in domain_get_uri(), so we don't see something like http://example.com/node, http://a.example.com/node in the domain switcher when we are in the front page.

One more thing that I am thinking now. In the domain_prefix_domainpath(), it's not needed to do the path lookup if the target domain id is equal to the active domain id (ie: $domain_id == $_domain['domain_id']). Because it is just duplicating the job of drupal_get_path_alias(). We just need to return the original aliased path but then we need to pass it to the function.

I am not really getting the problem you mentioned. How can you get two separate aliases, you have 2 separate aliases for the path in same url_alias table? Mind giving me some examples.

agentrickard’s picture

I mean 'two separate aliases (on two different prefixed domains) for the same path that is not a node path.'

New patch committed. Nice fixes.

ariflukito’s picture

hmm right but that's a rare case unless you construct the URL yourself, it won't be any problem. I believe if you want to have menu links that span multiple domains, you need to give the absolute URLs there and those URLs don't get passed to url() function.

One more thing that I am thinking now. In the domain_prefix_domainpath(), it's not needed to do the path lookup if the target domain id is equal to the active domain id (ie: $domain_id == $_domain['domain_id']). Because it is just duplicating the job of drupal_get_path_alias(). We just need to return the original aliased path but then we need to pass it to the function.

what do you think about this one? Just to clarify the last part, add the original alias to the hook's argument.

agentrickard’s picture

I think that needs to be accounted for. Committed to HEAD.

function domain_prefix_domainpath($domain_id, &$path, $path_language = NULL) {
  global $language, $_domain;
  // $map[$domain_id] keys are Drupal paths and the values are the corresponding aliases
  static $map = array(), $count = array(), $status = array(), $tablename = array();

  // If the alias is for the current domain, do nothing.
  if ($domain_id == $_domain['domain_id']) {
    return;
  }
// ... rest of function ...
ariflukito’s picture

The problem with that is it will just return the original path (node/$nid) not the original aliased path.

$path = domain_path($target_domain_id, $original_path, isset($options['language']) ? $options['language']->language : '');

See we only pass the $original_path to the hook.

ariflukito’s picture

StatusFileSize
new2.13 KB

new custom_url_rewrite_outbound.patch for d5

agentrickard’s picture

So you mean:

  // If the alias is for the current domain, do nothing.
  if ($domain_id == $_domain['domain_id']) {
    $path = drupal_get_path_alias($path);
    return;
  }
ariflukito’s picture

no something like this

$path = domain_path($target_domain_id, $original_path, $original_alias, isset($options['language']) ? $options['language']->language : '');

function domain_prefix_domainpath($domain_id, &$path, $original_alias, $path_language = NULL) {

  //snip..

  // If the alias is for the current domain, do nothing.
  if ($domain_id == $_domain['domain_id']) {
    return  $original_alias;
  }

  //snip..
}
agentrickard’s picture

Status: Patch (to be ported) » Needs work

Ah. I didn't see the extra parameter in the function. This will have to wait until I get home.

ariflukito’s picture

I added the extra paramater, it is not in the original function.

agentrickard’s picture

If we do this check inside domain_path() itself, do we need to worry about the $original_path var?

ariflukito’s picture

If we do the check inside domain_path() then there will be no path altering for all paths to current domain. That's not a problem for domain prefix but I don't know if other modules will need it.

Also I think probably it's not a good way to pass the path by reference, the other hook implementations will get the altered path instead of the original one.

ariflukito’s picture

StatusFileSize
new759 bytes
new8.1 KB

here is patch for D5 port and small fix for D6 (wrong table naming when we have global prefix)

note: in domain_prefix_table_exists(), we don't need to call db_escape_table() explicitly since db_table_exists() is going to do it for us.

agentrickard’s picture

Version: 6.x-2.0-rc4 » 6.x-2.0-rc5
Status: Needs work » Patch (to be ported)

The small D6 patch has been committed. Marking as to be ported.

agentrickard’s picture

Version: 6.x-2.0-rc5 » 6.x-2.0-rc6
Status: Patch (to be ported) » Needs review

I just committed a change to HEAD, since we were accidentally dropping language paths.

So this needs a retest.

agentrickard’s picture

Status: Needs review » Fixed

This will need to be tested post-release, it appears.

ariflukito’s picture

Version: 6.x-2.0-rc6 » 5.x-1.9
Status: Fixed » Patch (to be ported)
StatusFileSize
new8.6 KB

this hasn't been ported to D5 and custom_url_rewrite_outbound.patch from #40 is needed to make sure custom_url_rewrite_outbound is called after drupal_get_path_alias.

agentrickard’s picture

Version: 5.x-1.9 » 5.x-1.10
Status: Patch (to be ported) » Needs review
agentrickard’s picture

Status: Needs review » Needs work
StatusFileSize
new6.69 KB

Here's the patch from #51 revised for 5.x-dev.

I am confused about the note referring to #40.

Can you simply update the patch file with the changes to the custom_url patch?

ariflukito’s picture

Hi Ken, in your revised patch it doesn't include the added new file domain_prefix.path.inc

The patch on #40 is meant to replace the custom_url patch. What the patch actually does is change the code flow so that the custom_url_rewrite_outbound function is called after drupal_get_path_alias since both functions modify the $path.

agentrickard’s picture

Can you re-roll?

ariflukito’s picture

The patch on #51 still applies cleanly but I reroll anyway

I attach 2 custom_url_rewrite_outbound.patch
- the first one is a reroll of #40, it's basically a backport from D6
- the second one is smaller patch, it works as well based on my test

ariflukito’s picture

Status: Needs work » Needs review
agentrickard’s picture

Status: Needs review » Patch (to be ported)
TimAlsop’s picture

Can somebody confirm if this patch is only available for D5 and not yet ported to D6 ?

Thanks,
Tim

TimAlsop’s picture

I have a few different domains which I use to access my company website, e.g. example.com, anotherexample.com and yetanotherexample.com. I also have sub domains for each domain, e.g. support.example.com, support.anotherexample.com and support.yetanotherexample.com. On some content which is shown in the main domain (e.g. example.com, anotherexample.com and yetanotherexample.com) I might refer to a page by URL (e.g. http://support.anotherexample.com/node/123). I am therefore looking for a way to make this URL get modified (re-written) so if a user logs onto example.com site and clicks on this link, it is changed to http://support.example.com/node/123. If I don't do this, the user will be taken to another domain, which I don't want, and also it means they have to logon again because of cookie_domain. So, is this patch/feature discussed in this issue, what I need, or have I missunderstood the use case ?

croryx’s picture

The thread indicates that the main patch was against D6 and was committed to 6.x-2.0-rc6. The port in question is a backport to D5.

TimAlsop’s picture

Croryx,

Ok, thanks for confirming. Since I am using 2.1, it seems the patch will be included already. In that case, I am not sure why it is not working for me. Maybe I have missunderstood what it does ??? Does my example in #60 help ?

Thanks,
Tim

croryx’s picture

Tim - you should probably start a new issue for this as this is a separate (though certainly related) topic. The maintainers will be more likely to see it that way and they won't have to sift through the 60 messages in the current thread. I don't do anything like this, but if you haven't looked at the sub-module Domain Source yet, that's where I'd start.

TimAlsop’s picture

Thankyou for your advice. I will create new issue.

agentrickard’s picture

@TimAlsop. Confirming that this thread is about something totally different.

joshmiller’s picture

Somewhat related... these linking issues are moot if $db_prefix is broken when using SSO...

#947298: SSO, Pathauto, and Domain_prefix are not compatible

Josh

agentrickard’s picture

Status: Patch (to be ported) » Closed (fixed)

D5 is closed.