Answers.Body: <p><code>{{ siteUrl }}</code> should do the trick for you.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-13T17:28:56.100Z
Answers.Text: This gives the URL of the site I'm on, not the default site in a mult-site installation.
Answers.UserDisplayName: Vaughn D. Taylor
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-10T18:55:47.677Z
Answers.LastActivityDate: 2018-08-10T18:55:47.677Z
Answers.UserDisplayName: andrew.welch
Answers.Body: <p>You can output the primary site’s Base URL like this:</p>
  
  
  
  <pre class="lang-twig prettyprint-override"><code>{{ craft.app.sites.primarySite.baseUrl }}
  </code></pre>
  
  <p>(<code>craft.app.sites</code> maps to <a href="https://docs.craftcms.com/api/v3/craft-services-sites.html" rel="noreferrer">craft\services\Sites</a>.)</p>
  
  <p>If your Base URL begins with an <a href="https://docs.craftcms.com/v3/config/#aliases" rel="noreferrer">alias</a>, you will need to parse it:</p>
  
  <pre class="lang-twig prettyprint-override"><code>{{ alias(craft.app.sites.primarySite.baseUrl) }}
  </code></pre>
  
  <p>Altertatively, if you need to link to a sub-page of the primary site (not just its Base URL), you can do that with the <a href="https://docs.craftcms.com/v3/dev/functions.html#siteurl-path-params-scheme-siteid" rel="noreferrer">siteUrl()</a> function, which has a <code>siteId</code> argument.</p>
  
  <pre class="lang-twig prettyprint-override"><code>{% set primary = craft.app.sites.primarySite %}
  {{ siteUrl('sub/path', siteId=primary.id) }}
  </code></pre>
  
  <p>Note that if your primary site’s Base URL contains the <code>@web</code> alias, that will always just return the host info for the current request. So you may need to replace that with a hard-coded base URL (or use a custom <a href="https://docs.craftcms.com/v3/config/#aliases" rel="noreferrer">alias</a>) before this works as expected.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-13T17:32:19.857Z
Answers.Text: This also gives the URL of the site I'm on, not the default site in a multi-site installation. The default site in my multi-site installation is www, and I have 5 subdomains. So, when I'm on blog.mysite.com and I use url(), I get blog.mysite.com -- this is not what I'm looking for. What I really want is www.mysite.com -- the default site in the multi-site installation.
Answers.UserDisplayName: Vaughn D. Taylor
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-13T22:04:01.243Z
Answers.Text: @VaughnD.Taylor Sorry, misunderstood your question. By “default” I take it you meant the primary site. Updated your question and my answer.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-11T17:09:41.870Z
Answers.LastActivityDate: 2018-08-13T23:00:28.780Z
Answers.LastEditDate: 2018-08-13T23:00:28.780Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>Is there an available variable for the primary site URL in a multi-site CraftCMS setup? I need a variable that I can attach to my logo that will take the user back to the primary site. I could hard code this, however, the URL needs to be environment aware. For example, on my local environment, the link should be <a href="https://www.mysite.local" rel="nofollow noreferrer">https://www.mysite.local</a> and when on development, the link should be <a href="https://www.mysite.dev" rel="nofollow noreferrer">https://www.mysite.dev</a>.</p>
  
Tags: <multi-site><siteurl>
Title: How do I get the primary site URL?
ThreadText: # How do I get the primary site URL?
  
  (Asked by: username_0 on 2018-08-10)
  
  Is there an available variable for the primary site URL in a multi-site CraftCMS setup? I need a variable that I can attach to my logo that will take the user back to the primary site. I could hard code this, however, the URL needs to be environment aware. For example, on my local environment, the link should be <https://www.mysite.local> and when on development, the link should be <https://www.mysite.dev>.
  
  **Tags:** multi-site, siteurl
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2018-08-11. Score: 9 | Accepted answer
  
  You can output the primary site’s Base URL like this:
  
  ```twig
  {{ craft.app.sites.primarySite.baseUrl }}
  
  ```
  
  (`craft.app.sites` maps to [craft\services\Sites](https://docs.craftcms.com/api/v3/craft-services-sites.html).)
  
  If your Base URL begins with an [alias](https://docs.craftcms.com/v3/config/#aliases), you will need to parse it:
  
  ```twig
  {{ alias(craft.app.sites.primarySite.baseUrl) }}
  
  ```
  
  Altertatively, if you need to link to a sub-page of the primary site (not just its Base URL), you can do that with the [siteUrl()](https://docs.craftcms.com/v3/dev/functions.html#siteurl-path-params-scheme-siteid) function, which has a `siteId` argument.
  
  ```twig
  {% set primary = craft.app.sites.primarySite %}
  {{ siteUrl('sub/path', siteId=primary.id) }}
  
  ```
  
  Note that if your primary site’s Base URL contains the `@web` alias, that will always just return the host info for the current request. So you may need to replace that with a hard-coded base URL (or use a custom [alias](https://docs.craftcms.com/v3/config/#aliases)) before this works as expected.
  
  > **Comments:**
  > **username_0**: This also gives the URL of the site I'm on, not the default site in a multi-site installation. The default site in my multi-site installation is www, and I have 5 subdomains. So, when I'm on blog.mysite.com and I use url(), I get blog.mysite.com -- this is not what I'm looking for. What I really want is www.mysite.com -- the default site in the multi-site installation.  
  > **username_2**: @VaughnD.username_0 Sorry, misunderstood your question. By “default” I take it you meant the primary site. Updated your question and my answer.  
  
  ---
  
  ### Answer by username_1 on 2018-08-10. Score: 4
  
  `{{ siteUrl }}` should do the trick for you.
  
  > **Comments:**
  > **username_0**: This gives the URL of the site I'm on, not the default site in a mult-site installation.  
  
  ---
  
  