7

I have a setup with multi sites that are separate domains.

site-a.com

site-b.com

I would also like to have assets separate for each site, like so:

site-a.com/images/picture1.jpg

site-b.com/images/picture2.jpg

I tried setting up aliases for each site, but just couldn't get it to work. Managed to get only one set of aliases to work, in the general.php file, under '*'. But cannot get aliases to be different for each site, like @web for example.

How would i setup the general.php or volumes.php or env.php to have separate assets for each site?

Additional notes:

I am using the latest version of Craft 3 (Craft CMS 3.0.23.1).

PHP 7.2

The setting "Propagate entries across all enabled sites?" in section is enabled.

The setting "Manage relations on a per-site basis" for asset field is enabled.

1
  • Have you tried setting the asset paths to just /images ? Dec 19, 2018 at 1:03

2 Answers 2

3

When you're creating a new local asset volume, you choose a file system path. I use both the site handle and the section handle in the path. For example:

/assets/<SiteHandle>/images/<SectionHandle>

Or, referencing your example (and using 'blog' as a section in your site):

/assets/site1/images/blog

I find that it's important to divide up the assets this way so that if you need to migrate content or backup, it will be much easier to figure out which assets go with which content.

If the sites share images in common (eg. social icons), I usually make a common folder to hold these above the site level in assets:

/assets/common/images

But I ultimately recommend that instead of local storage, you use Amazon S3 Buckets. It's relatively simple to set up and you'll see much better performance from Amazon's CDNs. You can use this same concept outlined for local files on Amazon S3.

1
  • 1
    How do you add in the <SiteHandle> like that? Are there hardcoded asset volumes for each Site or is there a way to echo it out? Can't seem to figure it out using @aliases or {twigvars}. Apr 23, 2019 at 19:50
1

I had the same question and here is a way to have assets in separate root folders using aliases with Site handles: How do I dynamically define Asset Volumes' Base URLs for different Sites?

Your Answer

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

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