1

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.

ojsglobal
  • 525
  • 1
  • 6
  • 31

6 Answers6

1

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.

Tobias
  • 7,238
  • 10
  • 46
  • 77
0

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.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

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

brummfondel
  • 1,202
  • 1
  • 8
  • 11
0

You can this way,

http://serverip/~sitefolder/imagesfolder/images.jpg

but @Tobiask method is better than this.

aurora
  • 24
  • 4
0

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" />
  • I think this won´t work on most servers that are secure enough to disallow the access to other user folders. – Tobias Jun 11 '14 at 11:11
  • This relies on there public html folder being exposed at "~username". It looked as if that was the case. However it may still not be a correct solution.. – Torbjorn Diderholm Jun 11 '14 at 11:19
0

You may be able to use

ln -s path/on/server/image.jpg image.jpg

Works on my default apache setup.