Steps to reproduce:

1) Install Domain Access.
2) Install Subfolders Domain.
3) Enable both modules with needed dependencies.
4) Enable Domain Source (not needed?).
5) Create a main domain at "example.com/".
6) Create a subdomain at "example.com/subfolder".
7) Enable "Rewrite all URLs to point to a single source".
8) Enable "Force domain editing from the primary domain".
9) Create a new node at "example.com/", also published at "example.com/subfolder".
> Notice: Don't select "Send to all affiliates", there's a bug with it in Subfolders Domain.
10) Go to "example.com/subfolder" and edit the content from there.
11) Preview the edition.

Expected behaviour:
- Node is accessed at "example.com/subfolder/node".
- Node is edited at "example.com/node/edit".
- Preview is shown at "example.com/node/edit".

Actual behaviour:
- Node is accessed at "example.com/subfolder/node".
- Node is edited at "example.com/subfolder/node/edit".
- Preview is shown at "example.com/subfolder/subfolder/node/edit".

I think this is related to Domain Access URL rewrite considering "/subfolder" is part of the path. It should check the actual domain (subfolder) name for this to work as expected.

As a side comment, I think the functionality of Subfolders Domain should've been integrated in Domain Access from start instead of a separated module. It helps you to work in development environments without DNS and also makes easier migrations from multi-sites, which can be installed at subfolders.

Best regards,
EmuAGR

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

EmuAGR created an issue. See original summary.

alvgalrus’s picture

Issue summary: View changes
alvgalrus’s picture

I've been looking in the code and I found the problematic function: domain_get_path($domain)

Subfolders Domain creates the subdomains at {domain}.subdomain like "example.com/subfolder1" and "example.com/subfolder2". I create a new node "node/1", published in both subdomains but sourced to "example.com/subfolder1".

When I follow the link to "node/1" from "example.com/subfolder2", Domain Access changes $base_url, so it effectively points to a single source, as follows (simplified):

domain_get_path() @ domain.module:
$url = parse_url($base_url);
$path = 'http://' . $domain['subdomain'] . $url['path'];

domain_url_outbound_alter() @ settings_custom_url.inc:
$domain[$nid] = domain_get_node_match($nid); //It contains $path as ['path'].
$options['base_url'] = $domain[$nid]['path'] . '/';

That way code ends adding the old path "subfolder2/node/1" to the new domain "example.com/subfolder1", endlessly making subfolders like this: example.com/subfolder1/subfolder2/node/1

My initial suggestion would be commenting $url['path'] in the $path variable assignation. That works for me but it might break other use cases I'm not thinking about.

alvgalrus’s picture

Status: Active » Needs review
FileSize
452 bytes

Attaching better thought patch.

agentrickard’s picture

Project: Domain » Subfolders Domain (sub domains)
Version: 7.x-3.12 » 7.x-2.8
Status: Needs review » Needs work

No. We never add module-specific workarounds in the code.

This needs to be addressed by Subfolders Domain, likely by altering the path element of the domain after it is generated by this function.

alvgalrus’s picture

I think there's no way to know if $base_url should be rewritten after this function has changed it. An editor could create a node alias with name subfolder2 inside domain subfolder1.

Check these URL which Domain Access will output, despite meaning different things. Let our current domain be example.com/subfolder3:

example.com/subfolder1/subfolder2
Meaning: Node "subfolder2" is inside the new domain "example.com/subfolder1".

example.com/subfolder1/subfolder2
Meaning: Node "subfolder1/subfolder2" inside new domain "example.com".

Subfolders Domain would read the new path. What is going to do? Domain Access is telling it "absolute path for a domain" is the path of the URL.

agentrickard’s picture

You can adjust that with hook_domain_load(), which fires after the base path is set.

alvgalrus’s picture

Just as a note, $base_path is not affecting in this rewrite issue. What is being changed is $base_url.

alvgalrus’s picture

I've been "playing" with hook_domain_load() until now, and I could more or less fix the issue by adding the following line of code:
$domain['path'] = domain_check_scheme($domain['scheme']) . '://' . $domain['subdomain'];

But then I needed a more difficult fix for forms and I didn't find comfortable to remove the path from them.

So I discovered way that I think should be a better solution for both modules:
$url['path'] in function domain_get_path() becomes request_path().
$action['path'] in function domain_form_alter() becomes "/".request_path().
Everything in domain.module.

In my opinion, this would indeed simplify path parsing and make it more robust. If this idea makes @agentrickard more comfortable, I can provide a more in depth patch.