Reputation: 534
I have two domains sitting on a single server, and I want to use images from domain A, on domain B.
However, I don't want users of domain B to know that the images are being pulled from domain A.
So insetad of putting:
<img src = "http://DOMAIN A/image.jpg">
I'd prefer to do something like:
<img src = "path/on/server/image.jpg">
...but I that doesn't work - I definitely have the correct path:
/home/username/public_html/images/image.jpg
as perform a file_exists on the image first with that path.
As an alternative, I've tried using:
<img src="data:image/jpg;base64,...">
But there are alot of images and this method is super slow.
Upvotes: 1
Views: 2263
Reputation: 21
You may be able to use
ln -s path/on/server/image.jpg image.jpg
Works on my default apache setup.
Upvotes: 0
Reputation: 21
Yes, you can do use relative url paths:
if your html document is located at
/home/username/public_html/index.html
use
<img src="images/image.jpg" />
if it is on a different user account, and yours is located at http://host.com/~username/index.html you can use
<img src="../~otherusername/images/image.jpg" />
Upvotes: 0
Reputation: 7380
You can use a redirect on the server, e.g. via mod_rewrite. Just redirect a special folder from server A to server B.
Try something like (on server A, inside a .htaccess file if you´re on an Apache web server):
RewriteEngine on
RewriteRule ^/img/(.+) http://server-b.com/img/$1 [R,L]
Then you can point to server A in the HTML, but the server redirects this to server B behind the scenes.
Or check the Apache documentation of rewriting for further information.
Upvotes: 1
Reputation: 24
You can this way,
http://serverip/~sitefolder/
imagesfolder/images.jpg
but @Tobiask method is better than this.
Upvotes: 0
Reputation: 1210
That's not possible as the image tag is executed by the client. You may add some kind of symlinks in the web server directory of B to point to the files of A.
Or use apache alias option to locate the files (like the cgi-bin does):
http://httpd.apache.org/docs/current/mod/mod_alias.html#alias
Upvotes: 0
Reputation: 944545
No. HTTP clients have no access to the file system of the computer the HTTP server is running on.
If you want to hide the domain where the image is hosted, then you have to provide a different URL (on a different domain) to it.
Upvotes: 0