更换无效的图像URL以404图像 [英] Replace invalid image url with 404 image

查看:233
本文介绍了更换无效的图像URL以404图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这是可以或不可以,我有我自己做了一个形象的主机。我需要一些最后的调整吧。

I don't know if this is possible or not, I have an image host that I've made myself. I need some last tweaks with it.

每当图像已被删除或无效的图像的URL,它应该有一个404图像替换,所以举例来说,如果有人添加了这一点:

Whenever an image has been deleted or is an invalid image url, it should replace with an 404 image, so for example if someone adds this:

http://imagehosturl.com/i/34njk5n.jpg

但它是一个无效的链接,所以我需要它来显示:

But it's an invalid link, so I need it to show:

http://imagehosturl.com/img/notfound.jpg

这是这样的:

我知道的.htaccess 能做到这一点与它的的ErrorDocument 404 ,但我有一个已经当用户到一个无效的页面访问,因此它会显示404页。

I do know that .htaccess can do this with it's ErrorDocument 404, but I have one already when a user access to an invalid page, so it would show the 404 page.

因此​​,只要用户热链接的图像和它的无效或者被删除,我需要它来替换为404的图像。

So whenever a user hotlinks an image and it's invalid or is deleted, I need it to be replaced with the 404 image.

我怎样才能让这个?

推荐答案

下面是一个潜在的答案:

Here's one potential answer:

RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule \.(gif|jpe?g|png|bmp) /path/to/logo.gif [NC,L]

另一种方法是使用自定义脚本页面:

Another is to use a custom scripted page:

使用ErrorDocument指令   (记录在[httpd.apache.org])来   点了'404'错误的脚本(Perl中,   PHP,等等)。如果所请求的文件   具有图像扩展(或具有   图片/ * MIMETYPE; PHP提供的   mime_content_type [us2.php.net]   功能这一点;我敢肯定有   很多方法可以做到这一点的Perl;该   MIME ::类型[search.cpan.org]模块   是一种方法),然后设置   内容类型头到MIMETYPE   您的标志形象和返回   该logoimage的内容   浏览器。

Use the errorDocument directive (documented at [httpd.apache.org ]) to point a '404' error to a script (perl, PHP, whatever). If the requested file has an image extension (or has an image/* mimetype; PHP supplies the mime_content_type [us2.php.net] function for this; I'm sure there are many ways to do this in perl; the MIME::Types [search.cpan.org] module is one way), then set the "Content-Type" header to the mimetype of your logo image and return the content of the logoimage to the browser.

<一个href="http://www.webmasterworld.com/forum92/3458.htm">http://www.webmasterworld.com/forum92/3458.htm

这篇关于更换无效的图像URL以404图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆