Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirecting image to php page

Tags:

php

apache

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.

like image 294
Searock Avatar asked Jun 17 '10 19:06

Searock


2 Answers

Looks like a use case for mod rewrite

with something like:

RewriteRule /images/(.*).gif$ images.php?img=$1
like image 51
Aif Avatar answered Oct 12 '22 11:10

Aif


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.

like image 29
Maerlyn Avatar answered Oct 12 '22 10:10

Maerlyn