Use live assets Directory for Dev site

HI there,

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:

if (!defined('MODX_ASSETS_PATH')) {
    $modx_assets_path= '/home/site/';
    $modx_assets_url= '/assets/';
    define('MODX_ASSETS_PATH', $modx_assets_path);
    define('MODX_ASSETS_URL', $modx_assets_url);


if (!defined('MODX_ASSETS_PATH')) {
    $modx_assets_path= '/home/site/public_html/assets/';
    $modx_assets_url= '';
    define('MODX_ASSETS_PATH', $modx_assets_path);
    define('MODX_ASSETS_URL', $modx_assets_url);

and I have emptied the cache, but it doesn’t work.

What am I doing wrong?


I’m wondering if perhaps it’s the media sources I should update instead?

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?

Thanks. Yes I did clear the cache (but not a stupid question as that’s tripped me up in the past!)

Did you mean an absolute path in the media source settings?

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.

Ah OK - I thought I was being clever!
I will see if I can do a rewrite via .htaccess.

Thanks Bob!

Yes the media source.

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.

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?

So so the subdomain isn’t inside the public_html directory - which could be part of the issue?
It’s alongside it.

the path of the broken image is:

So it’s no different to the original. (which makes me wonder what this setting actually does?)

I haven’t changed any of the paths in the media sources because it uses a relative path, but I will try an absolute path.

Creating a plugin is beyond my knowledge so I haven’t tried that, but I will see if I can work out how to create it.

I tried changing the media source base path and base uri to:

and also changed the basePathRelative to NO.

After clearing the cache, the path to the images is now:


So we are close, but it has a forward slash before the URL of each image.

to see the real path just open the console, right click to the image path and click on open in new tab.
in that case you will see something like:


Leave everything as it was and try this:

  • not sure if it’s exactly like this but let’s test it:

Plugin :: OnWebPagePrerender

// Get the current content
$content = $modx->resource->getContent();

// Replace the string
$newContent = str_replace('', '/', $content);

// Update the resource content

return true;

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:

but any pages which are pulling image thuumbnails using pdoresources or getResources look like this:


And some pages which have images in the content field look like this:

So i’m wondering if it’s a media source issue?

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! :sweat_smile:

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.

try this one with errors:

// Get the current content
$content = $modx->resource->getContent();

// Check if content exists
if (!empty($content)) {
    // Replace the string
    $newContent = str_replace('', '', $content);

    // Update the resource content
    // 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! :slight_smile:

Thanks for your help and advice on this :slight_smile:

What’s the TV type you’re using?