简体   繁体   English

禁止直接访问图片网址

[英]Prohibit direct access to images URL

I have a blog with images. 我有一个图片博客。 I do not want that the images are directly accessible through the URL (and also not for Googlebot and other bots)... for example... mysite.com/assets/images/img1... etc. So I thought to password protect the images directory with .htaccess. 我不希望图像可以通过URL直接访问(而且Googlebot和其他机器人也不能访问)...例如... mysite.com/assets/images/img1 ...等。所以我想输入密码使用.htaccess保护图像目录。 That worked, only front-end all my images became links, and I had to provide my credentials to make them show. 那行得通,只有前端所有我的图像都变成了链接,我必须提供凭据才能显示它们。 How can I make my images show yet NOT make them directly accessible when typing the corresponding URL and the images URLs (or better yet the images directory) NOT accesible for bots to crawl/index? 当键入相应的URL并且图像URL(或更好的images目录)不能被机器人抓取/索引时,如何显示我的图像而又不能直接访问它们?

Don't go with password protection. 不要使用密码保护。 The right way to do it would be to filter the requests based on the referer URL. 正确的方法是根据引荐来源网址过滤请求。 If the request originates from your own site then it's ok. 如果请求来自您自己的站点,则可以。 Otherwise the request is trying to get an image directly. 否则,请求将尝试直接获取图像。

I've found this site with detailed instructions on how to do that: http://altlab.com/htaccess_tutorial.html 我发现此站点包含有关如何执行此操作的详细说明: http : //altlab.com/htaccess_tutorial.html

Taken from the mentioned site: 取自上述站点:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ http://url_to_default_image.gif [L]

Note that you would have to enable mod_rewrite in your Apache server. 请注意,您必须在Apache服务器中启用mod_rewrite

Btw, just asking. 顺便说一句,只是问。 Why don't just let people get the image directly if they want to? 为什么不让人们直接获得图像呢?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM