I am working on a facelift of a site, so have duplicated the live site, and installed it on a subdomain.
But - I have so many images in the site, that I don’t have enough space in my hosting plan.
I thought I could read the images from the live site, to save duplicating them all, by editing the Assets path in the Core > config file from:
What you did here make a lot of sense, have you tried absolute path in the media resource?
It might not display the thumbnails in the manager but might just work well in the frontend.
this is stupid but did you clear cache after the change?
As you can see from the “before” code above, the assets_url is not really a URL. It’s really a path to the assets directory from the site root. I think MODX prepends the site_url to it when using it (which won’t help you). I don’t think what you’re trying to do can be done that way. I could be wrong.
You should be able to do it with a clever rewrite rule in .htaccess, though you’d have to craft it so it wouldn’t apply to non-image files.
You could also do it with a plugin that rewrites the <img src="local/assets/" attribute in the tags of your Resources.
is your RewriteEngine On pointing to the root or the subfolder?
RewriteBase /
I think that is reference to what Bob is talking about, there is not way to point to the images if the .htaccess is saying something else, isn’t?.
The other question is, changing the ‘MODX_ASSETS_PATH’ the images are not loading but what is the path to image showing?
Did you sorted this out? I think it’s a good something to know.
Cheers.
Ah OK.
The RewriteBase is pointing to the root of the subdomain (it’s not a subfolder).
After changing the ‘MODX_ASSETS_PATH’ the path to the image doesn’t change - it’s still looking in the original location. It’s like the setting has no effect.
It’s pointing to the root but if you are in a sub-domain that means you are in a different folder isn’t?
I was thinking if you are in the same hosting the hosting path should be enough to share it between sites, because it’s the same one. But looks like that is not the way!
and what is the path of the broken image, with the MODX_ASSETS_PATH modified?
What about the plugin to change the paths of the images?
On webPrerender or something like that?
Thanks for your time on this.
The plugin doesn’t seem to do anything though.
But with the plugin disabled, I just noticed that some images are displaying, but others aren’t.
So some have the path:
Did you crated a new media resource or modified the existing one?
is there more than one?
I imagine pdoresources is going to use the default path config to display the images.
just be sure the images are being displayed are not inside the dev folders, otherwise nothing different is happening!
may be try to put the plugin code in an snippet on the top of the page?
It’s the original media source - there’s two in total.
I think I’m getting in a bit of a muddle now! I will put the plugin as a snippet and see how that works.
<?php
// Get the current content
$content = $modx->resource->getContent();
// Check if content exists
if (!empty($content)) {
// Replace the string
$newContent = str_replace('https://www.domain.com/assets/', 'https://www.dev.domain.com/assets/', $content);
// Update the resource content
$modx->resource->setContent($newContent);
// Save the resource
if ($modx->resource->save()) {
return true;
} else {
$modx->log(modX::LOG_LEVEL_ERROR, 'Error saving resource content in OnWebPagePrerender plugin.');
return false;
}
} else {
$modx->log(modX::LOG_LEVEL_ERROR, 'No content found in the resource in OnWebPagePrerender plugin.');
return false;
}
Before going to any more trouble, see if you can generate a URL that shows an image that exists only in the alternate location, and that will show the image when pasted into the Browser’s address window.
If your alternate location is not under public_html, images in it may not be accessible no matter what you do.
Thanks Bob. So yes I can get an image showing correctly, even though the subdomain folder is outside of public_html.
The images which are read directly from the TV on the page are rendering correctly.
But, if I call the same page into it’s parent category page using pdoResources, the image is broken.
If I add &processTVs=image - the path is correct!
There are still broken images, but these are ones which are hard coded into the template, so I guess I can’t work around that.
So this is a half solution, which should be OK.
I don’t fully understand WHY the processTVs fixes it, but I’m sure you do!