0

I'm building a Craft site locally and I'm unsure how to handle a path issue that will occur when the site goes live.

My understanding is that in a live implementation, the /web/ folder will become the root folder. In twig templates, I can exclude /web/ from paths by using {{ siteURL }}, i.e. {{ siteURL }}images/.

However, you can't use Twig when adding page content through Redactor. So if I want to include an image with the page text, I have to use "/web/" in the path. When the site goes live, those paths will be broken since the /web/ folder will become the root.

How can I resolve this without having to change all the links to remove /web/ once the site is live? I feel like there must be a configuration file or setting somewhere I can change, but I haven't been able to find one.

4
  • 2
    How do you develop locally? Normally you also have a webserver (e.g. MAMP Pro or some Vagrant or the hot new Nitro thing) running locally which is using the /web/ folder as docRoot. So it should behave exactly the same way as on the live system. Commented Jul 4, 2020 at 20:17
  • Ahh, I wasn't even thinking about it being an issue with the webserver settings, I was thinking it was a configuration issue somewhere in Craft. I set the wrong root directory when I created the virtual host in MAMP. Thanks!
    – Jake1293
    Commented Jul 5, 2020 at 15:23
  • Maybe use @web alias and the pass output of redactor field through {{alias()}} function? Thanks to that, @web will be always resolved as root url. Commented Jul 7, 2020 at 1:13
  • Thanks for the suggestion, I'll look into that for future use. I ended up solving this issue by editing my .env file and removing "web" from the site root path. This was my first Craft site so I didn't understand at the time I set it up that the /web/ folder should be the root, not the project folder.
    – Jake1293
    Commented Jul 7, 2020 at 20:09

0

Your Answer

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

Browse other questions tagged or ask your own question.