Вопрос

I have restricted hotlinking my files in using htaccess. But I need those files to be displayed in Google Doc Viewer. In htaccess I allow Google Docs to hotlink my files, but it is not working. Please help me in this Below is the code I used in my htaccess file

RewriteEngine on RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomainname.com/ [NC] RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?docs.google.com [NC] RewriteCond %{REQUEST_URI} !hotlink\.(gif|png|jpg|doc|ppt|xls|pdf|html|htm|xlsx|docx|pptx|swf) [NC] RewriteRule .*\.(gif|png|jpg|doc|ppt|xls|pdf|html|htm|xlsx|docx|pptx|swf)$ http://mydomainname.com/ [NC]

Это было полезно?

Решение

Oliver S is correct, but maybe the name of the user agent is changed now.. I tried

RewriteCond %{HTTP_USER_AGENT} !(.*Google.*)

And it worked perfectly

Другие советы

Using the referrer from https urls will probably not be very successful. Note also that the remote in the googledocs are not fetched by the browser from your server, but from a server process at google.

I had the same problem and the trick I found was to allow a specific User-Agent:

RewriteCond %{HTTP_USER_AGENT} !(.*Feedfetcher-Google.*)

Of course it is easily spoofable, but in "normal usage" your hotlink protection will still work.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top