2013-04-16 2 views
2

내 이미지의 보호를 구현하려고하는데 내 코드에 어떤 문제가 있습니까?.htaccess 핫 링크 보호를 구현하는 방법

// If referral is from google but NOT from "http://www.google.com/blank.html", redirect home 
RewriteCond %{HTTP_USER_AGENT} !(googlebot|bingbot|Baiduspider) [NC] //If user agent is NOT bot 
RewriteCond %{HTTP_REFERER} !^$          //Allow blank referral 
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?google.com [NC]  //if referral is from google 
RewriteCond %{HTTP_REFERER} ^http://www.google.com/blank.html$  //if referral is NOT from that url 
RewriteRule http://www.mydomain.com/ [R,L]       //redirect home 


// If referral is from my domain and accessing images, do nothing 
RewriteCond %{HTTP_USER_AGENT} !(googlebot|bingbot|Baiduspider) [NC] //If user agent isn't bot 
RewriteCond %{HTTP_REFERER} !^$          //Allow blank referral 
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mydomain.com [NC] //if referral is from my domain 
RewriteCond %{REQUEST_URI} !(^|&)images(&|$)       //if URL contains string "images" 
RewriteRule ^.*$ - [NC,L]           // DO nothing 


// If referral is NOT from my domain and accessing images, show watermarked image 
RewriteCond %{HTTP_USER_AGENT} !(googlebot|bingbot|Baiduspider) [NC] //If user agent isn't bot 
RewriteCond %{HTTP_REFERER} !^$          //Allow blank referral 
RewriteCond %{HTTP_REFERER} mydomain.com        //if referral is NOT from my domain 
RewriteCond %{REQUEST_URI} !(^|&)images(&|$)       //if URL contains string "images" 
RewriteRule ^images/(.*)$ http://www.mydomain.com/cache/$1 [NC,R,L] //redirect to watermarked image 

나는 꽤 많은 단계를 this answer의 2를 만들려고 해요,하지만 난에 문제가 있어요 "같음에"와 "같지 않음에"나는 PHP와 출신으로! 연산자가 같지 않음에 사용됩니다.

도와 줄 사람이 있습니까?

답변

2

두 번째 규칙 집합은 암시적인 허용입니다. 리디렉션 또는 액세스 금지없이 요청을 통과합니다. 즉, "원하는"조건 목록을 제공한다는 의미입니다. 또한 일치하는 "이미지"가 %{REQUEST_URI} 변수의 일부가 아닌 쿼리 문자열에있는 것처럼 보입니다. %{QUERY_STRING} 변수를 확인해야합니다.

뭔가 같은 :

// If referral is from my domain and accessing images, do nothing 
RewriteCond %{HTTP_USER_AGENT} !(googlebot|bingbot|Baiduspider) [NC] //If user agent isn't bot 
RewriteCond %{HTTP_REFERER} ^$ [OR]         //Allow blank referral 
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?mydomain.com [NC] //if referral is from my domain 
RewriteCond %{QUERY_STRING} (^|&)images.*?(&|$)      //if URL contains string "images" 
RewriteRule ^.*$ - [NC,L]           // DO nothing 

// If referral is NOT from my domain and accessing images, show watermarked image 
RewriteCond %{HTTP_USER_AGENT} !(googlebot|bingbot|Baiduspider) [NC] //If user agent isn't bot 
RewriteCond %{HTTP_REFERER} !^$          //Allow blank referral 
RewriteCond %{HTTP_REFERER} !mydomain.com       //if referral is NOT from my domain 
RewriteCond %{QUERY_STRING} (^|&)images.*?(&|$)      //if URL contains string "images" 
RewriteRule ^images/(.*)$ http://www.mydomain.com/cache/$1 [NC,R,L] //redirect to watermarked image 

images 일이 실제로 요청 URI가 아닌 쿼리 문자열의 일부인 경우이 방법이 없습니다 당신은 그것을에서 &을해야하고 당신에 대해 일치하는지의 . 이미지, & 이미지, 이미지 &, 또는 & 이미지 &하고 다른 아무것도, 만 4 possiblities 일치 (^|&)images(&|$) 정규식.

RewriteCond %{REQUEST_URI} /images/ 

또는

RewriteCond %{REQUEST_URI} !/images/ 
: 당신이 이미지 디렉토리에 대해 일치하려는 경우, 당신은 대신 이런 식으로 뭔가를 원하는
관련 문제