Forum Moderators: phranque
I need a script that redirects all image request to a mirror via imageredirector.php?i=<path to image> (this php script checks the mirrors every 5 mins, and redirects with header("Location: url"); function. If all mirrors are down, localhost (last mirror) should be used. The problem is the rewriterule for localhost requests:
RewriteRule ^(.+)\.(gif¦jpg¦png)$ imageredirector.php?i=$1.$2 [L]
GET /test.png -> Redirect to [localhost...] -> Redirect to [localhost...] -> Redirect to [localhost...] -> etc.... so, just an endless loop
is there any way to disable the RewriteRule if its the 2nd request for localhost?
You could test the {HTTP_HOST} variable and inhibit the rule if the hostname is localhost. Or you could 'tag' redirected requests by prepending or appending additional path information to indicate that it's already been redirected, and then strip that path information on the mirrors before serving the image.
Just remember that HTTP is a stateless protocol; The server has no memory of any previous HTTP requests. You can either change the requested URL to allow a RewriteRule to detect it for special handling, or you can use a cookie to server as a client-side 'memory'. This latter approach is what we call "sessions" in PHP.
Jim