2011-11-03 2 views
1

사진 웹 사이트를 시작하는 데 거의 다르고 내 이미지를 보호하고 싶습니다.이미지 보호를 위해 htaccess 사용

#Set FollowSymLinks, in most cases already set on the server 
Options +FollowSymLinks 
#Enable Indexes 
Options +Indexes 
#Turn on the Rewrite Engine 
RewriteEngine on 
#Allow my domain 
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?mydomain.com [NC] 
#Allow another domain 
#RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?anotherdomain.com [NC] 
#Allow blank referrers or delete this line to block them 
#Deleting this line also blocks access to images by filepaths 
RewriteCond %{HTTP_REFERER} !^$ 
#Allow search engines 
RewriteCond %{HTTP_REFERER} !google. [NC] 
RewriteCond %{HTTP_REFERER} !search?q=cache [NC] 
RewriteCond %{HTTP_REFERER} !msn. [NC] 
RewriteCond %{HTTP_REFERER} !yahoo. [NC] 
#File types to be blocked 
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L] 
#OR 
#First allow an image to be hotlinked to avoid looping 
#RewriteCond %{REQUEST_URI} !^mydomain.com/image/hotlinker.gif$ 
#Then display it as a custom image 
#RewriteRule .(jpg|jpeg|png|gif)$ mydomain.com/image/hotlinker.gif [NC,R,L] 

1) 빈 참조 사이트를 차단 포함하지 않는 그 파일 경로의 항목에 의해 호출되는 이미지를 막을 수있는 방법이 있나요 : 나는 웹 검색의 결과로 다음습니까? 몇 가지 예가 있지만 사이트 전체가 아니라이 작업을하고 싶습니다.

2) 내 이미지에 대한 Google, MSN 및 Yahoo의 적절한 액세스를 허용하는 올바른 코드가 있습니까?

3) 코드가 하나 이상의 소스에서 병합되었습니다. 구문에 대한 지식이 없으므로 대체 이미지가없는 첫 번째 RewriteRule이 두 번째가 아닌 \로 시작하는 이유는 무엇입니까?

의견을 보내 주셔서 감사합니다.

답변

3

1) 공백 참조자를 차단하지 않고 파일 경로를 입력하여 이미지를 호출하는 것을 중지 할 수 있습니까? 몇 가지 예가 있지만 사이트 전체가 아니라이 작업을하고 싶습니다.

나는 방법이 생각하지 않습니다,하지만 당신은 규칙에 별도의 세트한다 RewriteCond에서 예외를 나열 할 수 있습니다 : 예로부터 어떤 요청 이미지를 제외한 모든 빈 리퍼러를 차단하는 것이다

# Check to see if referer is blank 
RewriteCond %{HTTP_REFERER} ^$ 
# Check to see if it isn't one of the files we're going to allow blank referers 
RewriteCond %{REQUEST_URI} !^/images/allow_blank_referer/ 
RewriteCond %{REQUEST_URI} !profile_picture\.png$ 
# Block images 
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L] 

/images/allow_blank_referer/profile_picture.png으로 끝나는 이미지.

2) 내 이미지에 대한 Google, MSN 및 Yahoo의 올바른 액세스를 허용하는 올바른 코드가 있습니까?

아니, 당신이 당신의 .htaccess에있는이 라인 :

RewriteCond %{HTTP_REFERER} !google. [NC] 
RewriteCond %{HTTP_REFERER} !search?q=cache [NC] 
RewriteCond %{HTTP_REFERER} !msn. [NC] 
RewriteCond %{HTTP_REFERER} !yahoo. [NC] 

은 간단하게 할 수 구글/MSN/야후과 검색 캐시에서 링크 된 이미지를로드 사람들. 예를 들어, 누군가 이미지 검색을 수행하고 이미지 중 하나를 클릭하면 차단하지 않습니다.

RewriteCond %{HTTP_USER_AGENT} !googlebot [NC] 
RewriteCond %{HTTP_USER_AGENT} !msnbot [NC] 
RewriteCond ${HTTP_USER_AGENT} !slurp [NC] 

사람들을 : 당신은 구글, MSN을 보장하기 위해 수행 할 것와 야후 봇이 차단되지 않습니다 무엇

그 조건을 다시 아래에 삽입 할 수 있습니다, 예를 들어, HTTP_USER_AGENT를 확인하는 것입니다 그 3 가지 중 하나가 사용자 에이전트 (소리내어 먹는다 = 야후)에있는 경우 리퍼러 점검을 우회합니다, 당신은 내가 가진 코드 병합) http://www.robotstxt.org/db.html

3 같은 장소에서 사용자 에이전트의 목록을 얻을 수 있습니다 하나 이상의 출처에서. 구문에 대한 지식이 없으므로 대체 이미지가없는 첫 번째 RewriteRule이 두 번째가 아닌 \로 시작하는 이유는 무엇입니까?

첫 번째 문자는 "."문자를 이스케이프합니다. "." 정규 표현식에서 와일드 카드와 같은 것이 무엇이든 일치하고 "\"는 이스케이프 처리하여 "나는 와일드 카드가 아니라 마침표를 의미합니다"를 의미합니다. 누군가가 게으르므로 아마 RewriteRule에서 주석 처리 된 "\"이 누락되었습니다.그것은 여전히 ​​예를 들어 .gif으로 끝나는 요청과 일치하지만 첫 번째 RewriteRule은 그렇지 않은 경우 zgif으로 끝나는 것과도 일치합니다. 주석 처리 된 RewriteRule을 사용하려면 (RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]을 주석으로 처리하십시오), 그 첫 번째 기간 앞에 "\"를 두는 것이 좋습니다.

+0

감사합니다. Jon에게 도움을 주신 데, 고맙습니다. 나는 내 질문에 대한 대답으로 좀 더 게시했다. – martin

+0

내 자신의 질문에 대답하여 올바른 프로토콜을 따르지 않았다면 사과드립니다. 내가 어떻게 코멘트에 모두 들어갈 수 있는지는 몰랐다. – martin

+0

HTTP_REFERRER에 의지하는 것이 안전합니까? – Geo

0

따라서 루트 디렉토리에서 수정 된 코드는 다음과 같습니다. 내 질문 1)과 관련하여

#Set FollowSymLinks, in most cases already set on the server 
Options +FollowSymLinks 
#Enable Indexes 
Options +Indexes 
#Turn on the Rewrite Engine 
RewriteEngine on 
#Allow my domain 
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?mydomain.com [NC] 
#Allow another domain 
#RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?anotherdomain.com [NC] 
#Allow blank referrers or delete this line to block them 
#Deleting this line also blocks access to images by filepaths 
RewriteCond %{HTTP_REFERER} !^$ 
#Allow users to follow images from search engines 
RewriteCond %{HTTP_REFERER} !google. [NC] 
RewriteCond %{HTTP_REFERER} !search?q=cache [NC] 
RewriteCond %{HTTP_REFERER} !msn. [NC] 
RewriteCond %{HTTP_REFERER} !yahoo. [NC] 
#Ensure search engines aren't blocked from indexing images (slurp is yahoo) 
RewriteCond %{HTTP_USER_AGENT} !googlebot [NC] 
RewriteCond %{HTTP_USER_AGENT} !msnbot [NC] 
RewriteCond ${HTTP_USER_AGENT} !slurp [NC] 
#File types to be blocked 
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L] 
#OR 
#First allow an image to be hotlinked to avoid looping 
#RewriteCond %{REQUEST_URI} !^mydomain.com/image/hotlinker.gif$ 
#Then display a custom image 
#RewriteRule \.(jpg|jpeg|png|gif)$ mydomain.com/image/hotlinker.gif [NC,R,L] 

, 나는이 시나리오가 좀 보호를 제공하기 위해 노력하고 몇 가지 이미지가 포함 된 전용 폴더 (나는 모든 명백한 HTML을 수행하고 내가 알고있는 자바 스크립트 물건입니다 완전한 증거가 아님).

.htaccess 파일을 캐싱 또는 색인 생성을 중지하려면 (내 robots.txt가이를 방지해야 함에도 불구하고) 비어 있지 않은 참조자를 감지하고 파일 경로 제한을 적용 할 수 있습니까? 파일 경로를 통해 이미지를 검색 할 수있는 빈 레퍼런스를 남긴다.

내 htaccess로 위 내 질문에 따라 이런 일을 보일 것이다

<FilesMatch "\.(jpg|jpeg|png|gif|bmp)$"> 
Header set Cache-Control: "no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0" 
</FilesMatch> 
#Set FollowSymLinks, in most cases already set on the server 
Options +FollowSymLinks 
#Enable Indexes 
Options +Indexes 
#Turn on the Rewrite Engine 
RewriteEngine on 
#Allow my domain 
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?mydomain.com [NC] 
#TEST HERE IF THE USER IS NOT A BLANK REFERRER 
????????????????????????????? 
#IF NOT BLOCK ACCESS TO IMAGES BY ENTERING FILEPATH 
RewriteCond %{HTTP_REFERER} ^$ 
#File types to be blocked 
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L] 

나는이 말이 바랍니다. 감사합니다.

+0

보호 된 폴더에만 .htaccess를 두어 해당 폴더에만 영향을 미칠 수 있습니다. 게시 한 사람이 괜찮아 보입니다. –

관련 문제