Hi, I would like to have Apache serve up an alternate image if a requested image does not exist on the server. Is it possible to do this with .htaccess or the like? tia.
Try this. You can change the 404.php to whatever you have, but make sure you change it through out the entire .htaccess file. # 404 error handler ErrorDocument 404 /404.php RewriteEngine On # Is it the URI 404.php ? (ie was a 404 generated ?) RewriteCond %{REQUEST_URI} ^/404\.php$ # Yes, so we extract the original URI from the http request (ie the first line) RewriteCond %{THE_REQUEST} ^GET[[:space:]](.+)[[:space:]]HTTP/ [NC] # Here we simply set an enviroment variable to be used later, this variable will contain the original REQUEST_URI RewriteRule ^.*$ - [E=ERROR404:%1] # Was the 404 URI ending with .jpeg .jpg .gif or .png? (ie was it an image?) RewriteCond %{ENV:ERROR404} \.(jpe?g|gif|png)$ [NC] # Yes, redirect internally to "your foo image'' RewriteRule ^.*$ foo.gif [L] # Was the 404 URI ending with .html or .htm? (ie was it an html file ? ) RewriteCond %{ENV:ERROR404} \.(html?)$ # Yes, redirect internally to "your foo html file'' RewriteRule ^.*$ foo.html [L] # All other 404 requests that do not match the extensions used are redirected to 404.php Code (markup):