Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Arno Welzel Newsgroups: comp.lang.javascript Subject: Re: missing image error Date: Wed, 5 Aug 2020 07:49:00 +0200 Lines: 56 Message-ID: References: <20200804223822.48ab12d7@james.kirk.invalid> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: individual.net sse0ZoWdBGADh2N+4pAauQ6wwe2bMuRX8N5hyB9i7+v6CS9Rgg Cancel-Lock: sha1:xKohxGeMs9EWtDt48Gfxm4Sy2gs= In-Reply-To: <20200804223822.48ab12d7@james.kirk.invalid> Xref: csiph.com comp.lang.javascript:38657 James Kirk: > In Message: > Arno Welzel wrote: [...] >> The only way to avoid 404 errors would be a wrapper script on the >> *server* which will either return the actual image or a placeholder >> if the image can not be loaded: > >> > >> Where "server-side-loader" is a PHP script etc. which will try to >> load the specificed image file and if this is not possible return >> the placeholder. > > š¬šžš«všžš« šœšØš§šŸš¢š š®š«ššš­š¢šØš§ > > RewriteCond %{REQUEST_FILENAME} !-f > RewriteCond %{REQUEST_URI} /img/.*\.(jpg|png|svg)$ [NC] > RewriteRule . /img/funnyClown.jpg [L] > > If the server generates a listing. Yep - this is a more elegant solution if you use Apache. And this should also work without directory index enabled. Also see: But in addition you also need this: RewriteEngine on And just to be sure: the Apache rewrite module must also be enabled on the server. The above rules translate as following: 1) RewriteCond %{REQUEST_FILENAME} !-f If the requested resource is not an existing file 2) RewriteCond %{REQUEST_URI} /img/.*\.(jpg|png|svg)$ [NC] If the requested URI starts with "/img/" and ends with ".jpg", ".png" or ".svg". The flags [NC] are for "no case", so the path or extension can also be ".JPG" or the path may start with "/IMG/" as well. 3) RewriteRule . /img/funnyClown.jpg [L] Response with a temporary redirect (HTTP 302) to /img/funnyClown.jpg and stop evalulation any other rule following ([L]). -- Arno Welzel https://arnowelzel.de