0

Basically I want to serve "made" images from the subdomain for one of my File Upload locations.

I've seen a couple of posts on how you can use ce-img to handle local sub domains but they weren't fully on my wavelength and hence haven't had the "light bulb" moment.

I have setup a sub domain where the folder lives at the primary domains root folder:

var/myhost/mywebsite/ = mysite.com

var/myhost/mywebsite/siteassets/ = assets.mysite.com

Have configured one of the 'file' paths to use the sub domain to upload images to and it works - upload myimage.jpg and it appears at assets.mysite.com/folder1/myimage.jpg

$config['ce_image_src_regex'] = array( 'http://assets.mysite.com/' => var/myhost/mywebsite/.'/' );
$config['ce_image_made_regex'] = array( '^/' => 'http://assets.mysite.com/' );  

It seems no matter which configuration I use, it never really works, I've experimented that much I've now forgotten where I started.

Can someone enlighten me pls :)

1

Think you're missing some key CE Image config variables - ce_image_current_domain and ce_image_document_root.

I've got this setup using static.domain as the URL. Here's my config settings...

Set some variables...

$config['static_url']   = "http://static.${_SERVER['HTTP_HOST']}";
$config['static_path']   = "/...path-to.../static-ar/www/";

Set the upload paths in the config...

//###   Override existing Upload Settings   ###
$config['upload_preferences'] = array(
    1 => array(                                                             // ID of upload destination
        'name'        => 'Content Pages',                                    // Display name in control panel
        'server_path' => $config['static_path'].'images/content-pages/',  // Server path to upload directory
        'url'         => $config['static_url'].'/images/content-pages/'      // URL of upload directory
    ),
    2 => array(                                                             // ID of upload destination
        'name'        => 'Blog Content',                                    // Display name in control panel
        'server_path' => $config['static_path'].'images/blog/',  // Server path to upload directory
        'url'         => $config['static_url'].'/images/blog/'      // URL of upload directory
    ),
    3 => array(                                                             // ID of upload destination
        'name'        => 'Guide Imagery',                                    // Display name in control panel
        'server_path' => $config['static_path'].'images/guides/',  // Server path to upload directory
        'url'         => $config['static_url'].'/images/guides/'      // URL of upload directory
    )
);

Now the CE Image stuff...

$config['ce_image_current_domain']  = $config['static_url'];
$config['ce_image_document_root']   = $config['static_path'];
$config['ce_image_cache_dir']       = "images/generated/";
$config['ce_image_made_regex'] = array( '^/images/generated' => $config['static_url'].'/images/generated');
2
  • Thx heaps for the info, before I delve in, will this approach work serving some files from subdomain and others from normal domain. It looks as though you've moved all your assets to sub domain ? Oct 28 '14 at 23:40
  • I have been yes, doubtful you'd be able to generate some images on one domain and others on another if that's what you had in mind? Or put another way - all the CE Image generated images would need to be in the same location, albeit you could have the upload folders where ever. You could have Symlinks on the server to create mirrors elsewhere...? Oct 29 '14 at 9:36
0

I ended up changing things slightly to enable me to serve specific folders from a sub domain rather then all image folders.

Using a config-override I set the specific folder to point towards a folder in the sub-domain like this standard treatment:

4 => array(           // ID of upload destination
        'name'        => 'Heroes',   // Display name in control panel
        'server_path' => 'var/server/html/file-assets/assets/heroes/',
        'url'         => 'subdomain.domain.com/assets/heroes/',
        'allowed_types' => 'img', //Only allow images
        'max_width' => '2000' //Set a max width for image
    )

I then changed the cache_dir to reside under the subdomain server path, all assets will be cached to this folder which is fine, it's still relative.

$config['ce_image_cache_dir'] = '/file-assets/data/';

The folder structure is this:

/var/server/html (domain.com)

/var/server/html/file-assets (subdomain.domain.com)

/var/server/html/file-assets/assets/heroes/ (Is the base path for the files set above)

We then strip the subdomain part from any URL that includes a subdomain:

$config['ce_image_src_regex'] = array( 'subdomain.domain.com/' => '/var/server/html' );

The image gets manipulated and saved to the /file-assets/data folder declared above, which coincidentally can be served from a normal domain or subdomain.

We then check the made source to see if it comes from our "heroes" folder which is where we want subdomain images served from.

$config['ce_image_made_regex'] = array( 
        '^/file-assets/data/assets/heroes/' =>  'http:subdomain.domain.com/data/assets/heroes/');

Whilst somewhat convoluted to follow, this allows me to serve only one particular set of assets from a subdomain decreasing page load by a significant factor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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