Forum Moderators: phranque

Message Too Old, No Replies

Redirect if not exist

         

zoltan

4:02 pm on Dec 30, 2010 (gmt 0)

10+ Year Member



I use rsync to sync pictures between 2 servers. The rsync is running every hour.
The original subdomain of the pictures is photo1.mydomain.com. I rsync everything to photo2.mydomain.com.

Everything is OK with older pictures but I want to work with new pictures as well as I want to serve images from photo2.mydomain.com. I created a redirect.php file on photo2.mydomain.com:

<?php
header('HTTP/1.1 302 Found');
header('Location: [photo1.mydomain.com'.$_SERVER['REQUEST_URI'])...]
?>

The problem is how do I tell apache on photo2.mydomain.com to execute the redirect.php file if the file is not found on the server?

Thanks in advance for your help.

chrisdonahue

9:43 am on Jan 5, 2011 (gmt 0)

10+ Year Member



You could probably handle this with some type of origin service code, meaning, you're basically setting up the same CDN type of environment that many of us use to service sites with high traffic volumes. If you're replicating nodes, perhaps a class to check to see if the photo exists on the node and if not then it fetches it from the "origin" server, or photo1.mydomain.com, rather than using the header logic. Seems like this would probably be something better addressed in your application logic. Can you interface the app layer and create that type of rule?

jdMorgan

9:24 pm on Jan 5, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Both PHP and Apache mod_rewrite have facilities to check for "file exists."

If the files normally physically exist (i.e. they are not created by a script or retrieved from a database by a script), then that would likely be useful to solve your problem.

Jim