用 404 图片替换无效图片 url
我不知道这是否可能,我有一个我自己制作的图像主机。我需要对其进行一些最后的调整。
每当图像被删除或者是无效的图像 url 时,它应该替换为 404 图像,例如,如果有人添加以下内容:
但这是一个无效链接,所以我需要它显示:
这是这样的:
替代文本 http://tinypic.com/images/404.gif
我确实知道 .htaccess
可以用它的 ErrorDocument 404
来做到这一点,但是当用户访问无效页面时我已经有了一个,所以它会显示 404 页面。
因此,每当用户热链接图像并且该图像无效或被删除时,我需要将其替换为 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.
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:
But it's an invalid link, so I need it to show:
Which is like this:
alt text http://tinypic.com/images/404.gif
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.
So whenever a user hotlinks an image and it's invalid or is deleted, I need it to be replaced with the 404 image.
How can I make this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是一个可能的答案:
另一种方法是使用自定义脚本页面:
http://www.webmasterworld.com/forum92/3458.htm
Here's one potential answer:
Another is to use a custom scripted page:
http://www.webmasterworld.com/forum92/3458.htm
使用 Apache,您可以拥有多个 .htaccess 文件。因此,如果您的所有图像都存储在同一目录中,请在该目录内创建一个
.htaccess
文件并添加这将创建一个仅应用于您的图像目录及其子目录。
With Apache, you can have multiple .htaccess files. So, if all of your images are stored in the same directory, create an
.htaccess
file inside of that directory and addThis will create a custom 404 redirect that is applied only to your image directory, plus its subdirectories.
您可以将 ErrorDocument 与 FilesMatch 指令一起使用,
如果 404 图像 uri 包含 jpg png 或 gif/image.jpg请求延期。
您还可以将自定义图像或 html 标记添加到错误文档中:
You can use ErrorDocument with FilesMatch directive
This will show /image.jpg if a 404 image uri with jpg png or gif extension is requested.
you can also add your custom image or html markup to the errordocument :
根据 AdamH 的回答,您还应该输出
404 header
。这是我正在使用的,.htaccess
image404.php
According and in addition to AdamH's answer, you should output
404 header
. Here's what I'm using,.htaccess
image404.php