tags:

views:

75

answers:

3

Hi,

Is it possible to redirect a user to a php page and then redirect to different image, if the user is requesting for the image ?

For example if user requests for the image or if other website requests for the image, it should be redirected to the php page and then redirected to a different image.

Like if other website requests for http://example.com/images/a.gif, the website will get a different image i.e. http://example.com/images/b.gif.

Is it possible? Let me know if I am not clear with my problem.

Thanks.

+5  A: 

Looks like a use case for mod rewrite

with something like:

RewriteRule /images/(.*).gif$ images.php?img=$1
Aif
+2  A: 

Do you mean you want to redirect to a different image, if the request comes from outside your site? Then you need apache's mod_rewrite, and rules something like this:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://your\.site\.com/ [NC]
RewriteRule a.gif b.gif [L,R] 

It means: if the referer is not a part of your site, rewrite every request to a.gif to b.gif.

Maerlyn
Yes, you got it right : )
Searock
+2  A: 

The RewriteRule specified above would be best, if you're using Apache. You could do it either via the server's config files or through a .htaccess rule if your server supports it. For more info, look to Apache's modrewrite page (for version 2.2): http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html

If you're using IIS or another web server, they all allow similar redirects, they just have different ways of implementing them.

peelman