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?
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.
- 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.
- Create a PHP script and run it in your browser. It will look like this:
$target = 'uploads.php';
$shortcut = 'uploads';
If you need more details on this technique, I can provide them, but it seems fairly straightforward to me.