OK, here's a complete (non-tested :) version...
#!/usr/local/bin/perl -w
use strict;
use CGI;
my $q = new CGI;
my @image_extensions = qw(gif png jpg jpeg);
my $referer = $ENV{'HTTP_REFERER'};
my $user = $ENV{'REMOTE_ADDR'};
my $usercomp = $ENV{'REMOTE_HOST'};
my $url = $ENV{'REDIRECT_URL'};
my $gmt = gmtime(time);
if ($referer) {
open(FILE2,">>public/404.txt");
print FILE2 "$url|$referer|$user|$usercomp|$gmt\n";
close(FILE2);
}
for (@image_extensions) {
if ($url =~ /\.${_}$/) {
print $q->redirect(-uri=>'http://image.url/here.gif');
exit(0);
}
}
print $q->header,
$q->start_html,
$q->h1('Whoops!'),
$q->h3($url),
$q->p('That page does not exist. Please press your back button a
+nd try again.'),
$q->end_html;
exit(0);
cLive ;-)
--
seek(JOB,$$LA,0);
| [reply] [Watch: Dir/Any] [d/l] |
cLive, I love you and I want to have your babies. *MWAH* :)
| [reply] [Watch: Dir/Any] |
If you made that an internal redirect rather than an external redirect, the browser wouldn't have to pull a second hit from the server... the server would merely
substitute the image data.
...
for (@image_extensions) {
if ($url =~ /\.$_\z/) {
print $q->redirect("/image/url/here.gif");
exit 0;
}
}
...
Now, about them babies... {grin}
-- Randal L. Schwartz, Perl hacker | [reply] [Watch: Dir/Any] [d/l] |
But would that still work if people are linking to my pictures from other sites?
The load on the server doesn't matter, but as I log all the hits to the 404 page, the log file was growing enormous in a short space of time and I had to keep cleaning it out. When I told off the person who was generating the most hits, he got really annoyed at me, like it was MY fault that he was doing it wrong. But now every time he links to the wrong url, he'll have a picture there to tell him how stupid he is :)
| [reply] [Watch: Dir/Any] |