Cms: Multi-site locale in asset path => file not found

Created on 5 Feb 2020  路  12Comments  路  Source: statamic/cms

My sites config:

    'sites' => 
    [
        'de' => [
            'name' => config('app.name') . ' - DE',
            'locale' => 'de_DE',
            'url' => '/de/',
        ],
        'en' => [
            'name' => config('app.name') . ' - EN',
            'locale' => 'en_US',
            'url' => '/en/',
        ]
    ]

The asset path contains now the locale and the file could not be found.

https://domain.tld/de/path/to/file.jpg
multisite

Most helpful comment

Note to self:
https://github.com/statamic/cms/blob/master/src/Imaging/GlideUrlBuilder.php#L61
Removing the site url prepending "fixes" it - it doesn't prepend the site anymore, but it will need some more testing against multiple sites. Especially when using different domains.

I had the same issue where a localized multi-site was returning the wrong url for image assets in the non-default site. Your GlideUrlBuilder.php fix worked well. What kind of testing needs done to see this fix make it into the beta? Thanks!!

All 12 comments

Asset path where? Are you using a tag? Seeing something in the CP?

Please provide some more details.

The image is shown in the cp. The image is shown correctly in the frontend, if I remove the locale from path (/de). So I think, it's an mod_rewrite problem. For the assets the locale should not be added to the image path.

Got it, thanks.

Do you have a workaround for it? Would really help!

I think it's because the default site is a subdirectory (/de) and asset URLs are being generated relative to that. A workaround (not a great one) is to make your default site / instead of /de.

What are you expecting to be at the root though if both sites live in subdirectories?

Sorry, i think my issue was unclear, I try to explain it better.
I have a multi-site like in my ticket described. I've added an assets field for an image, using the default asset container. If I choose now an image and glide adds the locale to the image url. Without glide the url is correct and the image is shown.
Regular: /img/asset/image.jpg
Glide: /de/img/asset/image.jpg
So if I use glide, the image could not be found from the browser.

I understand that, but put aside the image stuff for a second. What are you expecting to see when you visit the root?

Note to self:
https://github.com/statamic/cms/blob/master/src/Imaging/GlideUrlBuilder.php#L61
Removing the site url prepending "fixes" it - it doesn't prepend the site anymore, but it will need some more testing against multiple sites. Especially when using different domains.

Note to self:
https://github.com/statamic/cms/blob/master/src/Imaging/GlideUrlBuilder.php#L61
Removing the site url prepending "fixes" it - it doesn't prepend the site anymore, but it will need some more testing against multiple sites. Especially when using different domains.

I had the same issue where a localized multi-site was returning the wrong url for image assets in the non-default site. Your GlideUrlBuilder.php fix worked well. What kind of testing needs done to see this fix make it into the beta? Thanks!!

I did use the following workaround:
https://github.com/statamic/cms/pull/1842

It seems, that it would be a cleaner solution to change the path here:
https://github.com/statamic/cms/blob/master/src/Imaging/GlideUrlBuilder.php#L61

Fixed by #2379

Was this page helpful?
0 / 5 - 0 ratings