<p><em>Maybe there's a better solution but:</em></p>
<p><code>{{ craft.app.request.absoluteUrl()|replace({'https://': &quot;https://www.&quot;}) }}</code></p>
<p><a href="https://twig.symfony.com/doc/3.x/filters/replace.html" rel="nofollow noreferrer">https://twig.symfony.com/doc/3.x/filters/replace.html</a></p>

CC BY-SA 4.0
2021-06-21T23:42:22.987Z
That works nicely, thank you!
Jake1293
CC BY-SA 4.0
2021-06-21T21:37:47.807Z
2021-06-21T21:37:47.807Z
user15280052
<p>How can I add &quot;www&quot; to the output of {{ craft.app.request.absoluteUrl }}?</p>
<p>In my .env file I have</p>
<pre><code>DEFAULT_SITE_URL=&quot;https://www.mysite.com&quot;
</code></pre>
<p>but</p>
<pre><code>{{ craft.app.request.absoluteUrl() }}
</code></pre>
<p>only outputs <a href="https://mysite.com" rel="nofollow noreferrer">https://mysite.com</a> without the &quot;www&quot;.  How can I fix that?</p>

CC BY-SA 4.0
2021-06-22T14:38:53.333Z
Craft will listen on whatever vhost you give it. Is your web server setup to redirect non-www to www?
RitterKnight
<url><siteurl><env>
Siteurl - craft.app.request.absoluteUrl() output missing "www"
# Siteurl - craft.app.request.absoluteUrl() output missing "www"

(Asked by: username_0 on 2021-06-21)

How can I add "www" to the output of {{ craft.app.request.absoluteUrl }}?
In my .env file I have
DEFAULT_SITE_URL="https://www.mysite.com"

but
{{ craft.app.request.absoluteUrl() }}

only outputs https://mysite.com without the "www".  How can I fix that?

**Tags:** url, siteurl, env

> **Comments:**
> **username_1**: Craft will listen on whatever vhost you give it. Is your web server setup to redirect non-www to www?  

---

## 1 answers

### Answer by username_2 on 2021-06-21. Score: 2

*Maybe there's a better solution but:*

`{{ craft.app.request.absoluteUrl()|replace({'https://': "https://www."}) }}`

<https://twig.symfony.com/doc/3.x/filters/replace.html>

> **Comments:**
> **username_0**: That works nicely, thank you!  

---

