Search

Okay, this is a question to all htaccess ninjas:

I've got a website with a lot of images that are processed with JIT but from time to time a file is missing on the server. I'd like to redirect all those JIT requests to non-existent files to a default placeholder image. How do I have to adjust the JIT redirecting rules to achieve this?

The upload field with the image has an attribute size.

if( Symphony cannot read/find the file )
    @size === unknown
else
    @size === size in bytes/bits

Use this attribute to either display the correct image or a placeholder. If the image is deleted but JIT still serves the cached version, well, at least it's an image :)

What if the files are not provided by an upload field at all :)

We create the image links on the fly using a product number provided by an Symphony input field. The files are uploaded manually via FTP.

Imo, XSLT is the place to put this logic. Can you modify the field to output file existence?

If not, it's a bit trickier, but doable.

Thanks for your input, but I really just want to adjust the .htaccess – no field hacking.

Ok, haven't got a Symphony installed here. Can you tell me what if anything is the output of a JIT transformation with no real file?

I mean, does it just fail, or is there text output.

It returns a 400 – Bad Request and an empty response.

My idea was to fetch missing images before the the URL is forwarded to the JIT processing. Something like: if image not found, return default, if image found pass it on to JIT.

I think that's nearly impossible in htaccess, or at least not in any way I know mod_rewrite to work.

It would have to be an extension thing, to allow a placeholder to be selected in the prefs, and then check for the existence of the file or a cached version, or show the placeholder.

I googled a bit and I was thinking about something like this, but I cannot get it to work:

RewriteCond %{REQUEST_URI} ^image/(.+.(jpg|gif|jpeg|png|bmp))$
RewriteCond %{DOCUMENT_ROOT}/workspace/%1 -f
RewriteRule ^(.*)$ extensions/jit_image_manipulation/lib/image.php?param=%1 [B,L,NC]
RewriteCond %{DOCUMENT_ROOT}/workspace/%1 !-f
RewriteRule ^(.*)$ workspace/path/to/my/placeholder.jpg [B,L,NC]

The idea is:

  • Check if the current URL points to a JIT image
  • Check if the requested file actually exists in workspace
  • If so, rewrite file to JIT
  • Check if the requested file doesn't exist in workspace
  • If so, rewrite file to placeholder

Would't it be nicer to change the load method and not playing around with rewrite rules :

if(!isfile($image) || !isreadable($image)){ throw new Exception(sprintf('Error loading image %s. Check it exists and is readable.', str_replace(DOCROOT, '', $image))); }

class.image.php static function load ()

btw. load seems to come to work, after no cache file is found.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details