Forum Moderators: phranque
if I, on my webpage, has an image-tag with no image to show, I would like to show an alternate image.
at the moment I have this:
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}!-f
RewriteRule .*\.(gif¦jpg¦jpeg¦bmp)$ img/notfound.jpg
but it doesn't seem to work.
I am quessing it's the %{request_uri} that should be replaced, but with what?
Welcome to WebmasterWorld!
REQUEST_FILENAME. If you change it, you may or may not need the DOCUMENT_ROOT path in front of it.
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteRule \.(gif¦jpe?g¦bmp)$ /img/notfound.jpg [L]
Use of the "file exists" check is inefficient. I'd suggest trying to fix as many broken images as possible before choosing to deploy this code. If there is any way to make the RewriteRule pattern more specific or to restrict the scope of this rule in other ways --for example if your images are all located in a subdirectory-- then do it.
Jim
I now changed my scritp to
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule ^.*\.(jpe?g¦bmp¦gif)$ /img/notfound.jpg [L,NC]
and it seems to be working
but...
what do you mean by
'Use of the "file exists" check is inefficient'?
I don't know of any other way to get the desired effect.!
regarding restricting the code.
I would like the code only to affect images that are placed on my pages.
meaning:
if you click an "image-link" on a page, it links to the image itself.
if the image doesn't exist, then with this code, the "notfound.jpg" image is displayed (alone).
what I would like is:
if the image doesn't exist, a 404 error occurs, and an E-mail is sent to me, informing me of the broken link/img-src
(Email is sent from my custom 404-errorpage)
I know that I should place another rewriteCond in the code, but I dont know what to test for, since I don't know exactly what the different %{...}-variables return
/Kasper
what do you mean by
'Use of the "file exists" check is inefficient'?
I don't know of any other way to get the desired effect.!
The trade-off is between usability and server performance, and only you can decide what a reasonable balance is. Consider *why* an image might be missing, and that may provide a way to limit the scope.
what I would like is:if the image doesn't exist, a 404 error occurs, and an E-mail is sent to me, informing me of the broken link/img-src
(Email is sent from my custom 404-errorpage)
Jim