Page 1 of 1

Replacing missing images with a default or placeholder... htaccess?

Posted: Thu Dec 30, 2010 4:17 pm
by rhiaro
Hey folks,

I have some images that are dynamically generated from variable names in a module.  Occasionally, one of them might not actually exist on the server yet, so I want a default image to appear in its place.

I've done some Googling and played about with htaccess, but can't make it work yet.  I added this:

 

Code: Select all

RewriteEngine on
  RewriteBase /cms/
RewriteCond %{REQUEST_URI} \.(jpg|jpeg|gif|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .*$ /uploads/images/icon_default.png [L]
to the .htaccess file in /docs/
But it doesn't appear to be working.
The path to the image is correct in relation to the CMSMS root (I tried it in relation to the htaccess file too, that didn't work either).  Do I need the/a htaccess file in a different place (such as the root)?

Any pointers?

Doing it with PHP seems like overkill...

I feel like there should be something built into CMSMS to achieve this; am I missing it?

Thanks!

Re: Replacing missing images with a default or placeholder... htaccess?

Posted: Thu Dec 30, 2010 4:53 pm
by ajprogramming
To use the .htaccess file it needs to be in root.

Re: Replacing missing images with a default or placeholder... htaccess?

Posted: Thu Dec 30, 2010 4:54 pm
by rhiaro
My CMSMS files aren't in the actual server root, would that be a problem?

Re: Replacing missing images with a default or placeholder... htaccess?

Posted: Thu Dec 30, 2010 5:44 pm
by ajprogramming
Sorry the root of your cms install. Should be the same as 

Code: Select all

RewriteBase /cms/