Forum Moderators: phranque

Message Too Old, No Replies

How do I redirect to "Image Not Available" picture?

Instead of small white box with red 'X'

         

sun818

11:02 pm on Dec 30, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have a lot of static HTML pages that link to images that no longer exist. Is it possible to load a "image not available" picture whenever the image is not on the server? I have access to Apache, .htaccess, and mod_rewrite

pendanticist

11:31 pm on Dec 30, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a lot of static HTML pages that link to images that no longer exist. Is it possible to load a "image not available" picture whenever the image is not on the server?

"...not on the server?" Your server, or theirs?

First thing that comes to my mind is: Would it not be better to simply treat it like one would link rot and just remove the dead link?

While I may not be clear on what you mean by 'static' pages, it is possible to make up just a simple "The image you requested is no longer available thru this website." file should do. Even at that, the extra work seems redundant.

Pendanticist.

sun818

12:06 am on Dec 31, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



"...not on the server?" Your server, or theirs?

All images I link to are "local", on my web host.

link rot

That is a possibility.

I'm beginning to think what I want is not possible since the image link is on a static HTML page.

amoore

12:30 am on Dec 31, 2002 (gmt 0)

10+ Year Member



one thing you can do is use a custom 404 handler. If they seem to be requesting a page, send them a 404. If they seem to be requesting an image, send them the one you want.

I'm not sure if you're using apache, mod_perl, or what, but you should be able to write a custom 404 handler.

txbakers

1:17 am on Dec 31, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why not create a new image with the name of the missing link?

jdMorgan

1:32 am on Dec 31, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or use mod_rewrite or Redirect to redirect all requests for nonexistent images to one "not available image" as you first asked? This is a fairly trivial rewrite excercise.

If it was my site, I'd fix or remove the bad links. Second choice would be to redirect the requests for unavailable images to a single replacement image. Last choice is a 404. IMHO, a 404 usually means a webmaster (referring or referred-to) needs to do something to fix a problem.

Jim

sun818

2:22 am on Dec 31, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Second choice would be to redirect the requests for unavailable images to a single replacement image.

Got code?

pendanticist

4:06 am on Dec 31, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If it was my site, I'd fix or remove the bad links. Second choice would be to redirect the requests for unavailable images to a single replacement image. Last choice is a 404.

That's pretty much what I suggested. Why fuss with something that surely falls under the 'routine maintenance' topic, unless there's something I'm unaware of when the distinctions being held to 'static'.

IMHO, a 404 usually means a webmaster (referring or referred-to) needs to do something to fix a problem.

<thwack!> :)

Correctamundo! Such a simple thing to create a custom 404 page and you can be as creative as you like too.

Too bad there are so many webmasters who pay inordinate attention to the front end of a website, while letting the really important stuff slide.

<Btw - Jim: I made it :)>

Pendanticist.

amoore

4:13 am on Dec 31, 2002 (gmt 0)

10+ Year Member



Got code?

Got cash?

jdMorgan

5:08 am on Dec 31, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey all, I'm certainly not trying to "thwack" anyone - just communicate a mindset here... There is 301, 302, 303, and 410 to tell user-agents exactly what the status of a "missing" file is, and 404 is sort of a last-ditch catch-all for situations where the site's webmaster hasn't specified the missing file's disposition - or where the problem is with an outgoing link on another site and the problem has not yet been discovered. I use 301, 302, and 303 redirects to respond to requests for relocated or replaced files, and I've got custom handlers for 403-, 404-, and 410-status files on my sites; I encourage all to do the same - I think it's a great idea, but YMMV.

Got code?

Sure I've got code - it's a fairly easy one; readers of the Apache documentation on mod_rewrite and mod_access will find that this problem is either a direct example, or can be easily derived from a given example.

Disclosure: I was a participant in an undeclared and informal "competition" to see who could come up with a clever rewrite to solve a posted problem the fastest. But after awhile, we were starting to post the same stuff to solve the same problems over and over again. Our wise and tolerant forum host [webmasterworld.com] asked us to "help those who help themselves", and "teach a man to fish so that he might eat for a lifetime", rather than "give a man a fish so that he might eat for a day", and that's what we've been trying to do.

A site search on WebmasterWorld for "mod_rewrite", "redirect", and ".htaccess" will turn up literally hundreds of similar posts. So, the goal is to help debug specific problems in snippets posted by members who've obviously done their homework, but who have hit an impasse - and thus to reduce repetitive postings.

Toward that end, there is also this fine new tutorial, Introduction to mod_rewrite [webmasterworld.com], which contains links to the Apache documentation, a regular-expressions tutorial, and other resources...

HTH,
Jim

sun818

5:12 am on Dec 31, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I originally asked this question because I run a web store on a web host with limited disk space (100MB). Currently the web site is at 95MB so I need to remove images associated with out of stock products when I add new products. But if out of stock products are available again, re-uploading those images is all I need to do.

I checked the forum for mod_rewrite image and mod_rewrite image redirect. All the discussion on redirects with images deal with hotlinking. What I want to do is to redirect (302) to a default image when the actual image is not found.

I'll keep looking [webmasterworld.com].

jdMorgan

7:14 am on Dec 31, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sun818,

Derived from the Redirect Failing URLs To Other Webserver example in the Apache 1.3 URL Rewriting Guide [httpd.apache.org]...

in .htaccess:

Options +FollowSymLinks
RewriteEngine on
# Redirect missing catalog images to a default image. Let other missing resource requests 404 normally.
RewriteCond %{REQUEST_URI} !-U # if requested resource doesn't exist
RewriteRule ^catalog_image_path/.*\.gif$ /default_image_path/default.gif [L] # redirect to default image

The cited Rewriting Guide is directly linked from the tutorial linked in msg #10 above. The warning about subrequest inefficiency applies but in this case, due to the way mod_rewrite only evaluates RewriteConds if the pattern of a RewriteRule is matched (Yes! - See mod_rewrite Ruleset Processing), the check-for-file-exists subrequest is invoked only for gif images in the catalog section. Make the catalog_image_path in the RewriteRule as specific as possible, and I suggest storing only product images (not common page graphics and spacer gifs, etc.!) in that path location, if possible. The redirect is "silent"; That is, the browser thinks that it is getting the requested gif, and is not told otherwise. If you really want to send a 302 response, then change the RewriteRule flag from [L] to [R=302,L].

HTH,
Jim

sun818

4:34 pm on Dec 31, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



thanks jd. Had very little success last night, will try again after the new year. Reading the following threads suggested that others not "do your homework" so I will try to solve issues myself before I post to the board:

Post Code [webmasterworld.com]
Posting code II [webmasterworld.com]

[edit]grammar error[/edit]

[edited by: sun818 at 5:38 pm (utc) on Dec. 31, 2002]

andreasfriedrich

5:11 pm on Dec 31, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I was a participant in an undeclared and informal "competition" to see who could come up with a clever rewrite to solve a posted problem the fastest.

Was there an undeclared and informal winner to this contest as well? ;)

jdMorgan

5:16 pm on Dec 31, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ya! Eine Berliner! :)

Jim

andreasfriedrich

5:28 pm on Dec 31, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think you won, Jim. Just have a look at your post count. ;) Anyway, it was fun while it lasted.

Ich wünsche allen einen guten Rutsch ins Neue Jahr.

A happy new year to everybody.

Andreas

gsx

9:50 pm on Dec 31, 2002 (gmt 0)

10+ Year Member



I use a perl script for a similar purpose. Create the html code as:
<a href="cgi-bin/image.pl?image=logo.jpg">

Then in the Perl file, load in logo.jpg (or whatever the parameter is) and send this file using Content-type: image/jpg header and then the file... or send an image missing file (that will always exist).

Disadvantages? Non - unless you want Google/FAST image search, I am not sure if these will index - I think Google will but FAST may struggle.