Forum Moderators: phranque

Message Too Old, No Replies

Rewrite img src to another domain

Within HTML page, rewrite images to another image server

         

patrickng01

1:59 pm on Apr 17, 2005 (gmt 0)

10+ Year Member



Hi,

I have an HTML page sitting on Server A (www.yyy.com):
[yyy.com...]

Within this page are img src references www.yyy.com/Image_library/Website_images/.....

(however, the images are actually located on another image server (apimg1) which actually does not have a public IP address and hence not accessible from the Internet. It has only internal IP address. Server A (has public IP address) and APIMG1 (no public IP address) are on the same LAN.

Hence, I had to do a rewrite to map all image src requests to the image server (apimg1).

RewriteCond %{HTTP_HOST} ^www\.yyy\.com [NC]
RewriteRule /Image_Library/Website_images/([^.]+)\.(gif¦jpg¦png)$ [apimg1...] [R=301,L]

However, the images still do not load. I check the Rewrite Log and notice that the URL www.yyy.com is not even detected (ie the RewriteCond is not happening). Is HTTP_HOST the correct variable to use or is it something else? My img src tags are all using the full url, ie. [yyy.com...] not relative paths (as the images are located in a separate image server)

thanks a lot

jdMorgan

2:38 pm on Apr 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll need to use the [P] flag in your RewriteRule to cause the public server to fetch the images from the back-end server on behalf of the user. Note that this causes the image data to 'pass' through the public server, so the main advantage is only with regard to storage, and not to server load.

See the RewriteRule documentation for a description of the [P] flag, and refer to Apache mod_proxy for more details.

Jim

patrickng01

1:26 pm on Apr 18, 2005 (gmt 0)

10+ Year Member



Hi,

I changed the RewriteRule to :

RewriteCond %{HTTP_HOST} ^www\.#*$!\.com [NC]
RewriteRule /Image_Library/Website_images/([^.]+)\.(gif¦jpg¦png)$ [apimg1...] [P]

the img src tags in the html page would look like this :

[xxx.com...]

but the logs are still not showing that these img srcs tags are processed at all. I even tried to use ProxyPass directives but that don't seem to work either.

ProxyRequests Off
<ProxyMatch /Image_Library/Website_images/([^.]+)\.(gif¦jpg¦png)$>
Order deny,allow
Allow from all
</ProxyMatch>

ProxyPass /Image_Library/Website_images/ [apimg1...]

pray tell me where I'd gone wrong.

thanks alot