1

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?

1
  • Craft will listen on whatever vhost you give it. Is your web server setup to redirect non-www to www? Commented Jun 22, 2021 at 14:38

1 Answer 1

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

1
  • That works nicely, thank you!
    – Jake1293
    Commented Jun 21, 2021 at 23:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.