Answers.Body: <p>this can happen if you use <code>@web</code> and let it auto determine your site URL for you. </p>
  
  <p>If you want to use <code>@web</code>, try <a href="https://docs.craftcms.com/v3/config/environments.html#using-aliases-in-control-panel-settings" rel="nofollow noreferrer">defining it</a> in your <code>config/general.php</code>. This would avoid auto determined URLs from getting stored in your cache.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-17T10:17:08.397Z
Answers.LastActivityDate: 2019-05-17T10:17:08.397Z
Answers.UserDisplayName: Oli
Answers.Body: <p>Looks like the problem was using <code>@web</code> for the 'Base URL' setting in 'Settings > Sites'.</p>
  
  <p>I replaced this with an environment variable <code>BASE_URL="https://www.domain.com"</code> defined in the .env file, and setting <code>$BASE_URL</code> in the 'Base URL' field. </p>
  
  <p>No idea why <code>@web</code> doesn't work reliably here, but so be it. </p>
  
  <p>Feel free to delete this question, but I thought I would leave it for others who may encounter the same problem.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-16T21:13:34.717Z
Answers.LastActivityDate: 2019-05-16T21:21:35.540Z
Answers.LastEditDate: 2019-05-16T21:21:35.540Z
Answers.UserDisplayName: Douglas McDonald
Body: <p>Forgive me if this is a server configuration or other issue unrelated to craft, but perhaps someone has some insight on what might be causing this, and how to fix it.</p>
  
  <p>When using a simple <code>category.getUrl()</code> for subnav, I am getting odd results where the subdomain is not 'www', but instead something else, like 'ddd' or 'w2w'. This is only happening in the production environment. And results vary depending on which page the nav is included on. Very strange.</p>
  
  <pre><code>{% set categories = craft.categories.group(group).all() %}
  {% for category in categories %}
      &lt;a href="{{ category.getUrl() }}"&gt;{{ category.title }}&lt;/a&gt;
  {% endfor %}
  </code></pre>
  
  <p>Any ideas are much appreciated? Thank you.</p>
  
Tags: <templating><craft3>
Title: Why is category.getUrl() returning incorrect subdomain?
ThreadText: # Why is category.getUrl() returning incorrect subdomain?
  
  (Asked by: username_0 on 2019-05-16)
  
  Forgive me if this is a server configuration or other issue unrelated to craft, but perhaps someone has some insight on what might be causing this, and how to fix it.
  
  When using a simple `category.getUrl()` for subnav, I am getting odd results where the subdomain is not 'www', but instead something else, like 'ddd' or 'w2w'. This is only happening in the production environment. And results vary depending on which page the nav is included on. Very strange.
  
  ```
  {% set categories = craft.categories.group(group).all() %}
  {% for category in categories %}
      <a href="{{ category.getUrl() }}">{{ category.title }}</a>
  {% endfor %}
  
  ```
  
  Any ideas are much appreciated? Thank you.
  
  **Tags:** templating, craft3
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2019-05-17. Score: 1 | Accepted answer
  
  this can happen if you use `@web` and let it auto determine your site URL for you.
  
  If you want to use `@web`, try [defining it](https://docs.craftcms.com/v3/config/environments.html#using-aliases-in-control-panel-settings) in your `config/general.php`. This would avoid auto determined URLs from getting stored in your cache.
  
  
  ---
  
  ### Answer by username_0 on 2019-05-16. Score: 1
  
  Looks like the problem was using `@web` for the 'Base URL' setting in 'Settings > Sites'.
  
  I replaced this with an environment variable `BASE_URL="https://www.domain.com"` defined in the .env file, and setting `$BASE_URL` in the 'Base URL' field.
  
  No idea why `@web` doesn't work reliably here, but so be it.
  
  Feel free to delete this question, but I thought I would leave it for others who may encounter the same problem.
  
  
  ---
  
  