Answers.Body: <p>I'm pretty sure the reason this is happening is because you did not set an absolute Base URL in your asset settings. So if you use <code>/assets/images/folder</code> in your asset settings, that's what the urls will look like on the frontend. If you instead use <code>http://my-project.com/assets/images/folder</code>, your asset urls will include the domain name.</p>
  
  <hr>
  
  <p>I'd recommend setting up <a href="https://docs.craftcms.com/v3/config/#aliases" rel="nofollow noreferrer">Yii Aliases in your config</a> (if you haven't already) and using those instead of hard-coding the url. So you'd do something like this in Craft's <code>general.php</code> config:</p>
  
  <pre><code>'aliases' =&gt; [
      '@assetBaseUrl' =&gt; 'http://my-project.com/assets',
      '@assetBasePath' =&gt; '/path/to/web/assets',
  ],
  </code></pre>
  
  <p>And then in your asset settings you'd be able to use <code>@assetBaseUrl/images/folder</code> instead of <code>http://my-project.com/assets/images/folder</code>. Just a way to keep everything as DRY and clean as possible </p>
  
  <hr>
  
  <p>The above solution should solve your issue, but fwiw, I'm pretty sure you can force your site to use absolute urls regardless of your asset settings. If you use the <code>url()</code> method and specify what scheme you want, I believe it will always resolve to an absolute url. So something like the following should work (but it feels very icky to me):</p>
  
  <pre><code>{% set seoImage = entry.featuredImage.one().getUrl('hero') %}
  {% set absoluteImageUrl = url(seoImage, '', 'https') %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-12T16:40:58.557Z
Answers.Text: Awesome! I like the aliases approach. I do have it set, but it's a relative path. No wonders. :)
Answers.UserDisplayName: Josh Coast
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-11T12:50:42.440Z
Answers.LastActivityDate: 2019-03-11T12:50:42.440Z
Answers.UserDisplayName: Jalen Davenport
Body: <p>I need the final tag to look like this:</p>
  
  <pre><code>&lt;meta property="og:image" content="http://mysite.com/uploads/resources/_hero/myimage.jpg"&gt;
  </code></pre>
  
  <p>If I use something like this:</p>
  
  <pre><code>{% set seoImage = entry.featuredImage.one().getUrl('hero') %}
  </code></pre>
  
  <p>I end up with a relative URL:</p>
  
  <pre><code>&lt;meta property="og:image" content="/uploads/resources/_hero/myimage.jpg"
  </code></pre>
  
  <p>So I thought "okay, I'll concatenate the site URL to the front and trim off one of the backslashes":</p>
  
  <pre><code>{% set seoImage = siteUrl ~ entry.featuredImage.one().getUrl('hero')|trim('/', 'left') %}
  </code></pre>
  
  <p>That worked fine until the server has to generate a new image using image transform. Then we end up, just the once, with a URL that looks like this:</p>
  
  <pre><code>&lt;meta property="og:image" content="http://mysite.com/http://mysite.com/index.php/actions/assets/generate-transform?transformId=46"&gt;"
  </code></pre>
  
  <p>Darn, No idea what to do from here. Any ideas on how to get an absolute URL for the OG image tag EVERY time? </p>
  
Tags: <templating><image-transforms>
Title: How can I set an absolute image url for Open Graph Image tags?
ThreadText: # How can I set an absolute image url for Open Graph Image tags?
  
  (Asked by: username_0 on 2019-03-09)
  
  I need the final tag to look like this:
  
  ```
  <meta property="og:image" content="http://mysite.com/uploads/resources/_hero/myimage.jpg">
  
  ```
  
  If I use something like this:
  
  ```
  {% set seoImage = entry.featuredImage.one().getUrl('hero') %}
  
  ```
  
  I end up with a relative URL:
  
  ```
  <meta property="og:image" content="/uploads/resources/_hero/myimage.jpg"
  
  ```
  
  So I thought "okay, I'll concatenate the site URL to the front and trim off one of the backslashes":
  
  ```
  {% set seoImage = siteUrl ~ entry.featuredImage.one().getUrl('hero')|trim('/', 'left') %}
  
  ```
  
  That worked fine until the server has to generate a new image using image transform. Then we end up, just the once, with a URL that looks like this:
  
  ```
  <meta property="og:image" content="http://mysite.com/http://mysite.com/index.php/actions/assets/generate-transform?transformId=46">"
  
  ```
  
  Darn, No idea what to do from here. Any ideas on how to get an absolute URL for the OG image tag EVERY time?
  
  **Tags:** templating, image-transforms
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-03-11. Score: 0 | Accepted answer
  
  I'm pretty sure the reason this is happening is because you did not set an absolute Base URL in your asset settings. So if you use `/assets/images/folder` in your asset settings, that's what the urls will look like on the frontend. If you instead use `http://my-project.com/assets/images/folder`, your asset urls will include the domain name.
  
  ---
  
  I'd recommend setting up [Yii Aliases in your config](https://docs.craftcms.com/v3/config/#aliases) (if you haven't already) and using those instead of hard-coding the url. So you'd do something like this in Craft's `general.php` config:
  
  ```
  'aliases' => [
      '@assetBaseUrl' => 'http://my-project.com/assets',
      '@assetBasePath' => '/path/to/web/assets',
  ],
  
  ```
  
  And then in your asset settings you'd be able to use `@assetBaseUrl/images/folder` instead of `http://my-project.com/assets/images/folder`. Just a way to keep everything as DRY and clean as possible
  
  ---
  
  The above solution should solve your issue, but fwiw, I'm pretty sure you can force your site to use absolute urls regardless of your asset settings. If you use the `url()` method and specify what scheme you want, I believe it will always resolve to an absolute url. So something like the following should work (but it feels very icky to me):
  
  ```
  {% set seoImage = entry.featuredImage.one().getUrl('hero') %}
  {% set absoluteImageUrl = url(seoImage, '', 'https') %}
  
  ```
  
  > **Comments:**
  > **username_0**: Awesome! I like the aliases approach. I do have it set, but it's a relative path. No wonders. :)  
  
  ---
  
  