Forum Moderators: phranque

Message Too Old, No Replies

.htaccess -- Serve different image based on IP range?

         

tkroll

3:36 am on Jun 20, 2005 (gmt 0)

10+ Year Member



Is it possible to serve a different image file to a browser based on IP range?

I can't use PHP or similar in this case. It will be a simple <img src='...'> tag.

Thanks!

jatar_k

7:56 pm on Jun 20, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



why can't you use php?

Chico_Loco

12:07 am on Jun 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



mod_rewrite to redirect to different images:

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/3.*
RewriteRule ^img\.jpg$ img.netscape.jpg [L]

RewriteCond %{HTTP_USER_AGENT} ^SomethingElse.*
RewriteRule ^img\.jpg$ img.otherbrowser.jpg [L]

All browsers I've used follow redirects for images and display them correctly, but perhaps older ones don't. Anyway, it's not a perfect way to do this, but if doing it at the source is not an option it is a solution.

tkroll

1:56 am on Jun 21, 2005 (gmt 0)

10+ Year Member



Thanks chico. That's sort of what I'm looking for. Can this be done based on the IP instead of on the user agent?

Chico_Loco

2:24 am on Jun 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



yes - using REMOTE_ADDR.