Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #38657
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: missing image error |
| Date | 2020-08-05 07:49 +0200 |
| Message-ID | <houvieFtnchU1@mid.individual.net> (permalink) |
| References | <mICdnUE2Q-twd7XCnZ2dnUU7-fvNnZ2d@westnet.com.au> <hoskjfFefplU1@mid.individual.net> <20200804223822.48ab12d7@james.kirk.invalid> |
James Kirk:
> In Message: <hoskjfFefplU1@mid.individual.net>
> Arno Welzel <usenet@arnowelzel.de> 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:
>
>> <img src="server-side-loader?image=myimage.jpg" ...>
>
>> 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: <https://httpd.apache.org/docs/2.4/rewrite/>
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
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
missing image error Andrew Poulos <ap_prog@hotmail.com> - 2020-08-04 14:58 +1000
Re: missing image error Arno Welzel <usenet@arnowelzel.de> - 2020-08-04 10:29 +0200
Re: missing image error James Kirk <noneya.invalid@gmail.com> - 2020-08-04 22:38 -0400
Re: missing image error Arno Welzel <usenet@arnowelzel.de> - 2020-08-05 07:49 +0200
Re: missing image error Julio Di Egidio <julio@diegidio.name> - 2020-08-04 02:18 -0700
Re: missing image error Andrew Poulos <ap_prog@hotmail.com> - 2020-08-05 13:20 +1000
Re: missing image error Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-08-05 08:44 +0200
Re: missing image error Andrew Poulos <ap_prog@hotmail.com> - 2020-08-05 18:02 +1000
Re: missing image error Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-08-05 10:18 +0200
Re: missing image error Julio Di Egidio <julio@diegidio.name> - 2020-08-05 02:36 -0700
csiph-web