Fork me on GitHub

Redirecting a browser image request  Bottom

  • My multiimage module presents random images from the database with a URL. For example, if you click this link, each time you refresh you will see a random image:
    http://curttimmerman…ge&group_name=_DEMO

    I have a request to add the capability to add external image links to this function. My question is: Can you redirect a browser request for an image? Are there any browser dependent implications of doing this?
  • Can you redirect a browser request for an image? You're asking if the server can do this; Yes. On Apache, the mod_rewrite (URL rewriting) module can do this easily, with a simple rule put in an .htaccess file. On IIS servers, there are commercial versions of the same, but obviously doesn't come standard.
    As if the module can do this in PHP, that depends on the module. If it works off a list of known images, it's a matter of using a full URL instead of a local file path. If it's just given a directory and told to display the contents randomly, then probably not, depends on your permissions for the remote server.

    For instance, off the top of my head, an htaccess rule in the image dir using Apache mod_rewrite:

    Code

    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule ^(.*)-ext\.(jpe?g|gif|png)$  http://www.example.com/images/. [R]
    Rewrites someimage-ext.jpg to
    http://www.example.com/images/someimage.jpg
  • Just to try to clarify what I am asking...

    The link above would be contained in a IMG HTML tag. It doesn't point to an image but invokes a module function that actually returns the image data.

    What if instead of returning the image, the function redirected the browser to a different link. Has anyone ever tried this?

    Thanks in advance,
  • Guess I can't help you much, I installed your module and put in a bunch of external image URLs, which it seems to handle just fine. I had the store in DB unchecked, so it should have gotten them externally.
    I don't know why you'd want to redirect the browser. That would take you away from the site altogether. All you'd want to do is change the image source, which is not a redirect. Whatever the backend does, and wherever it sources the image, the browser doesn't care, as long as it's fed standard HTML and image data, which is what PHP does. Unless you're talking Javascript, I can see no browser issues. You can have an iFrame if that's what you mean, and point it at whatever you want. They're a window into another page or site. But not really suitable here, I should think.

This list is based on users active over the last 60 minutes.