开发者

Redirecting image to php page

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 开发者_如何学Goimage, 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.


Looks like a use case for mod rewrite

with something like:

RewriteRule /images/(.*).gif$ images.php?img=$1


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜