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? Jun 22 at 14:38
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
    Jun 21 at 23:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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