Scenario
I have two domain records:

  • www.teach.org | National
  • dallasftworth.teach.org | Dallas - Ft. Worth

All organization CTs live on National (Domain Source), but their Domain Access is both National & Dallas-Ft. Worth, that way they're accessible from either subdomain. However, recently when we are on dallaftworth.teach.org and click a link that tries to redirect to an organization on www.teach.org (https://dallasftworth.teach.org/node/72 -> https://www.teach.org/organizations/coppell-independent-school-district) then I get this error:

Redirects to external URLs are not allowed by default, use \Drupal\Core\Routing\TrustedRedirectResponse for it.

I believe this is due to an issue in DomainSubscriber.php because both of the domain records hostnames should be in the Trusted Redirected Response, however Core's UrlHelper.php discerns each one to be external relative to the other thus far.

So in the meanwhile I've created a patch of UrlHelper.php to consider all domains + tlds as a part of the same Trusted local/internal URL. In the meanwhile, I wanted the communities opinion as to whether or not all domain records should be stored in the TrustedRedirectResponse classes $trustedUrls array to avert this issue for others in the future or if this should be solved at the core UrlHelper.php level.

CommentFileSizeAuthor
#2 2863184-1.patch2.19 KBdremy
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dremy created an issue. See original summary.

dremy’s picture

agentrickard’s picture

Domains should be set in the Trusted Host settings of settings.php.

DomainSubscriber.php uses TrustedRedirectRespose.

      if (isset($redirect_status)) {
        // Pass a redirect if necessary.
        $response = new TrustedRedirectResponse($domain_url, $redirect_status);
        $event->setResponse($response);
      }

See domain/README.md for instructions.

agentrickard’s picture

Category: Bug report » Support request

I don't think this is a bug. If you have both domains listed in your settings.php Trusted Host Settings, it should work as designed.

agentrickard’s picture

Status: Active » Closed (works as designed)
bas123’s picture

I am getting the same error but within the same domain.

This began when I moved the site from a Subdomain on the same account into production and added a redirect in .htaccess from /public_html/ to /public_html/site

Now the browser switches (seemingly) randomly between 'https://mywebsite/node_name' and 'https://mywebsite/site/node_name' and produces the error(s) with respect to authentication pages.

I will provide more specific details if someone will reply demonstrating an interest in helping solve the issue..

As so far it has not been responded to with my requests elsewhere!

auxiliaryjoel’s picture

@bsa123 Yes I'm having the same issue,
the public pages seem to load OK from the main domain (how that I've redirected to public_html/web in my public_html directory's .htaccess)
but if I add /user to the main domain in order to login in to Drupal, then I get this error.
I can login OK if I use the old/full path: domainname.com/web/user

But I'd love to know how to fix it so I don't have to?

auxiliaryjoel’s picture

#46 from this thread solved it for me:
https://www.drupal.org/project/drupal/issues/2612160#comment-12953709

BUT...

Now that I have this working,
I've noticed that my "git push..." no longer works.
It may be a coincidence, or it may be due to this redirect in place?

This is the git command I run:
git push origin2live master
note: this has worked on all other occasions for months,

I received an error.
At first I thought I may have had changes on server, so I tried to override them:
git push -f origin2live master

the error that I'm getting when trying to git push to my live shared hosting server is:

Counting objects: 13, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (13/13), done.
Writing objects: 100% (13/13), 1.21 KiB | 1.21 MiB/s, done.
Total 13 (delta 10), reused 0 (delta 0)
To path/to/my/repo/public_html/.git
! [remote rejected] master -> master (Working directory has unstaged changes)
error: failed to push some refs to 'ssh://path/to/my/repo/public_html/.git'

Has anyone else had experiences with this that relate to the changes as per #46?

shobhit_juyal’s picture

@auxiliaryjoel, thanks for giving that reference. I was also facing this issue and that solutions worked for me. Now I want to share what steps I did exactly.

1) Made host entry in /etc/hosts
2) Map directory upto the "....../web" in /etc/apache2/000-default.conf
3) Added below snippet in settings.php
```
if (isset($GLOBALS['request']) and
'/web/index.php' === $GLOBALS['request']->server->get('SCRIPT_NAME')) {
$GLOBALS['request']->server->set('SCRIPT_NAME', '/index.php');
}
```
4) Uncomment lines 119 and 123 in /web/.htaccess

And its working perfectly.

#drupalIndiaAssociation

developer-rocha’s picture

Thank you @shobhit_juyal
This is work for me.
I didn't have to uncomment the lines 119 and 123 in /web/.htaccess