I have a website with a lot of images and many of them are going to be used by two subdomains. I wanted to avoid uploading the same images twice, so I thought maybe to use the images from the domain.com for my sub.domain.com - is that possible and how?

  • Yes, it is possible. You simply need to use the domain name when defining the path of an image anywhere you use them, for example: http://example.com/path/to/image/file.jpg
    – Lodder
    Sep 30 '15 at 9:41
  • And how about galleries?
    – TheAdnan
    Sep 30 '15 at 10:11
  • Well it depends on the gallery extension you're using. Some may allow you to manually input the image path, where as other may require you to select the image from a list.
    – Lodder
    Sep 30 '15 at 10:16
  • This is something you'll need to contact the developer about as it's their extension
    – Lodder
    Sep 30 '15 at 10:45

If your sites are on Apache web server, you can share images folder from one site to the other, by creating symbolic links. With this technique I successfully created common images folder, which is shared by three Joomla sites on the same hosting server, without any problem.

I have used instructions from the following URL How to create a symbolic link in cPanel, by using method #2, creating PHP scripts:

Ever needed to create a symlink in cPanel? Well, cPanel itself doesn’t have any feature to work with symbolic links.

You just have to SSH into your server and execute the following command:

ln -s /path/to/target /path/to/shortcut

This will create a symbolic link for you.

What if SSH is not available? Unfortunately, FTP does not support creation of symbolic links.

There’re at least 2 more options you can try.

  1. Set up a cron job in cPanel with the linux command mentioned above.

Don’t forget to delete the cronjob after the symlink is created. Failing to do this will result in unpredictable issues.

  1. Create a PHP script and run it in your browser. It will look like this:

$target = 'uploads.php';
$shortcut = 'uploads';
symlink($target, $shortcut);
echo readlink($shortcut);

If you need more details on this technique, I can provide them, but it seems fairly straightforward to me.


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