Hello, I am looking for some script that will allow me to show different images to different people but using the same URL. OK, I think an example would be the best way to explain what I want to do, so here is an example. I have an image named "tech.jpg" and another one named "non-tech.jpg", now I want to use same URL, say: "http://mysite.com/img/mypic" and I want the script to return the first image "tech.jpg" if the request (user) came from (clicked the link from) Forums.DigitalPoint.com, otherwise the link would show the second image "non-tech.jpg". So how can I make the same URL show different images (I want the URL to return an image and NOT a page that contains the right image) to different people depening on the referring source?
A .htaccess file like this should work fine: RewriteEngine On RewriteCond %{HTTP_REFERER} !^http://(.+\.)?yoursite\.com/ [NC] RewriteRule !^(non-)(.*)\.jpg$ non-$1.jpg [L] PHP:
Thanks for your reply, Jim! But could you please explain how that works? I am not familiar with the .htaccess file and rewrite rules, so if I want to apply this code to my example above, how should it look like?
Enable mod_rewrite RewriteEngine On Set condition: Referer is not from mysite.com RewriteCond %{HTTP_REFERER} !^http://(.+\.)?yoursite\.com/ [NC] URL's not starting with non- and ending with .jpg, redirect to non-filname.jpg RewriteRule !^(non-)(.*)\.jpg$ non-$1.jpg [L] To make it work for your site, just change yoursite.com to your domain. Save it as .htaccess and put it in the folder you wish to have your images swapped on.
OK, so if I want to redirect URLs referred to my site from digitalpoint forums to "tech.jpg" and not "non-tech.jpg", do I use the following? RewriteEngine On RewriteCond %{HTTP_REFERER} http://(.+\.)?forums\.digitalpoint\.com/ [NC] RewriteRule (non-)(.*)\.jpg$ $1.jpg [L] Code (markup): I have some other questions please: 1- What does [NC], [L] at the end of the second, third lines mean? 2- Does the above redirect rules apply if the user came from a page deep in forums.digitalpoint.com, say "http://forums.digitalpoint.com/forumdisplay.php?f=15" or it just works if the user came from forums.digitalpoint.com? Thanks!
1)NC is case insensitive flag L is last rule flag 2) Add a ^ before the http:// and it should work for anything on the domain forums.digitalpoint.com