Answers.Body: <p>Drupal 8's architecture is different from most, and you probably know that there are two copies of some files - one in <code>libraries</code> and one in <code>vendor</code>.  My guess is that Mosaico is getting the path to <code>url.php</code> through two different functions that give different results.</p>
  <p>Open up your <code>civicrm.settings.php</code> and find the line that has <code>CIVICRM_UF_BASEURL</code> in it, and paste these three lines anywhere below that:</p>
  <pre><code>$civicrm_setting['URL Preferences']['userFrameworkResourceURL'] = CIVICRM_UF_BASEURL . '/libraries/civicrm/';
  $civicrm_paths['civicrm.root']['url'] = CIVICRM_UF_BASEURL . '/libraries/civicrm/';
  $civicrm_setting['domain']['userFrameworkResourceURL'] = CIVICRM_UF_BASEURL . '/libraries/civicrm/';
  </code></pre>
  <p>This should hopefully force Civi to always return the <code>libraries</code> folder when constructing URLs to the <code>extern</code> subfolder.</p>
  <p><strong>EDIT</strong>: Today I was troubleshooting a site that went from using the Roundearth install method to the civicrm-asset-plugin method, and I had to comment out these lines to get the site to work.  I suspect Mosaico will be fine without these lines now that I've completely converted.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-18T20:07:24.493Z
Answers.Text: Worked like a charm. Thanks.
Answers.UserDisplayName: Graham
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-18T21:37:53.920Z
Answers.Text: Hooray!  I actually just came back here to add [this PR](https://github.com/civicrm/civicrm-core/pull/19386) in case you were using URLs with tokens, which don't currently support tracking (but do with this patch).
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-19T21:55:56.367Z
Answers.Text: The other thing I would suggest is that you should check to see if you have the civicrm asset composer installed and use that as appropriate and also suggest changing the default extern url setting in Administer -> System Settings -> Url Settings to use the default router rather than the standalone scripts if you are on a version of CiviCRM that supports that.
Answers.UserDisplayName: Seamus Lee
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-28T17:43:03.350Z
Answers.Text: @Graham Note my edit above.
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-07T19:09:54.567Z
Answers.Text: @JonG-MegaphoneTech would this be the same issue if I'm seeing the same behaviour on WordPress?
Answers.UserDisplayName: Rose Lanigan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-08T04:32:04.683Z
Answers.Text: @RoseLanigan I'm afraid not.
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-10T11:41:22.783Z
Answers.Text: @JonG-MegaphoneTech thanks for the reply - turns out we had an erroneous 'index.php' set as a part of custom permalinks on WP, and when I removed that, it all worked beautifully!
Answers.UserDisplayName: Rose Lanigan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-14T18:13:14.847Z
Answers.Text: In fact, those lines have to be removed if you're on a non-roundearth install, or you have to add "core/" to them.
Answers.UserDisplayName: Alan Dixon
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-17T19:09:20.283Z
Answers.LastActivityDate: 2021-01-28T17:42:50.960Z
Answers.LastEditDate: 2021-01-28T17:42:50.960Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Body: <p>I've just started in on an issue with a D8 site, currently running Civi 5.25 and Mosaico 2.5.</p>
  <p>Emails sent using Mosaico with clickthrough tracking contain a mix of correct and incorrect URLs. If I add a URL to an image that has been placed in Mosaico, then that URLs get correctly converted to something like <a href="https://example.org/libraries/civicrm/extern/url.php?u=xxx&amp;qid=yyy" rel="nofollow noreferrer">https://example.org/libraries/civicrm/extern/url.php?u=xxx&amp;qid=yyy</a>
  Embedding a URL into text in the body of the email, and/or using a button with a URL, they get converted to an incorrect link, of the form <a href="https://example.org/vendor/civicrm/civicrm-core/extern/url.php?u=xxx&amp;qid=yyy" rel="nofollow noreferrer">https://example.org/vendor/civicrm/civicrm-core/extern/url.php?u=xxx&amp;qid=yyy</a> - and clearly these links lead only to 404s.</p>
  <p>If I construct a comparable email using the 'traditional' mailer then the resulting trackable URLs are all of the correct form.</p>
  <p>So it looks like Mosaico is doing something weird in terms of constructing the paths for some, but not all trackable URLs.</p>
  <p>I've looked at my settings for Directories and Resource URLs, and also looked at civicrm.settings.php and nothing is jumping out at me as being wrong.</p>
  <p>I'm not too familiar with D8/Civi, and neither do I know much of the history of the site, other than that I've just updated Mosaico from 2.3x to 2.5 in an unsuccessful effort to resolve this issue.</p>
  <p>Where is Mosaico getting the path data from? Why is it constructing some URLs that are fine, but others that are broken? Any clues gratefully received.</p>
  
Tags: <mosaico><click-through>
Title: How can I fix broken clickthrough URLs in Mosaico emails?
ThreadText: # How can I fix broken clickthrough URLs in Mosaico emails?
  
  (Asked by: username_0 on 2021-01-17)
  
  I've just started in on an issue with a D8 site, currently running Civi 5.25 and Mosaico 2.5.
  
  Emails sent using Mosaico with clickthrough tracking contain a mix of correct and incorrect URLs. If I add a URL to an image that has been placed in Mosaico, then that URLs get correctly converted to something like <https://example.org/libraries/civicrm/extern/url.php?u=xxx&qid=yyy>
  Embedding a URL into text in the body of the email, and/or using a button with a URL, they get converted to an incorrect link, of the form <https://example.org/vendor/civicrm/civicrm-core/extern/url.php?u=xxx&qid=yyy> - and clearly these links lead only to 404s.
  
  If I construct a comparable email using the 'traditional' mailer then the resulting trackable URLs are all of the correct form.
  
  So it looks like Mosaico is doing something weird in terms of constructing the paths for some, but not all trackable URLs.
  
  I've looked at my settings for Directories and Resource URLs, and also looked at civicrm.settings.php and nothing is jumping out at me as being wrong.
  
  I'm not too familiar with D8/Civi, and neither do I know much of the history of the site, other than that I've just updated Mosaico from 2.3x to 2.5 in an unsuccessful effort to resolve this issue.
  
  Where is Mosaico getting the path data from? Why is it constructing some URLs that are fine, but others that are broken? Any clues gratefully received.
  
  **Tags:** mosaico, click-through
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-01-17. Score: 5 | Accepted answer
  
  Drupal 8's architecture is different from most, and you probably know that there are two copies of some files - one in libraries and one in vendor.  My guess is that Mosaico is getting the path to url.php through two different functions that give different results.
  Open up your civicrm.settings.php and find the line that has CIVICRM_UF_BASEURL in it, and paste these three lines anywhere below that:
  $civicrm_setting['URL Preferences']['userFrameworkResourceURL'] = CIVICRM_UF_BASEURL . '/libraries/civicrm/';
  $civicrm_paths['civicrm.root']['url'] = CIVICRM_UF_BASEURL . '/libraries/civicrm/';
  $civicrm_setting['domain']['userFrameworkResourceURL'] = CIVICRM_UF_BASEURL . '/libraries/civicrm/';
  
  This should hopefully force Civi to always return the libraries folder when constructing URLs to the extern subfolder.
  EDIT: Today I was troubleshooting a site that went from using the Roundearth install method to the civicrm-asset-plugin method, and I had to comment out these lines to get the site to work.  I suspect Mosaico will be fine without these lines now that I've completely converted.
  
  > **Comments:**
  > **username_0**: Worked like a charm. Thanks.  
  > **username_1**: Hooray!  I actually just came back here to add [this PR](https://github.com/civicrm/civicrm-core/pull/19386) in case you were using URLs with tokens, which don't currently support tracking (but do with this patch).  
  > **username_2**: The other thing I would suggest is that you should check to see if you have the civicrm asset composer installed and use that as appropriate and also suggest changing the default extern url setting in Administer -> System Settings -> Url Settings to use the default router rather than the standalone scripts if you are on a version of CiviCRM that supports that.  
  > **username_1**: @username_0 Note my edit above.  
  > **username_3**: @JonG-MegaphoneTech would this be the same issue if I'm seeing the same behaviour on WordPress?  
  > **username_1**: @RoseLanigan I'm afraid not.  
  > **username_3**: @JonG-MegaphoneTech thanks for the reply - turns out we had an erroneous 'index.php' set as a part of custom permalinks on WP, and when I removed that, it all worked beautifully!  
  > **username_4**: In fact, those lines have to be removed if you're on a non-roundearth install, or you have to add "core/" to them.  
  
  ---
  
  