ホットリンク保護が機能していたので、と思いましたが、リファラーがローカルの場合はそうではありませんでした。
IndexIgnore *
Options +FollowSymlinks
RewriteEngine on
RewriteOptions MaxRedirects=10
RewriteCond %{REQUEST_URI} ^/image_dir/
RewriteCond %{REQUEST_URI} \.(png|gif|jpe?g)$ [NC]
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?domain.com/
RewriteRule ^(.*)$ /some_dir/some_file.php?querystring=$1 [L]
私が必要とするのは:
リファラーがサイトの画像リクエストで私のサイトからのものではない場合、ユーザーがリクエストしている画像を含むページにリダイレクトします。
リファラーが私のサイトからのもので、リクエストが image_dir 内の任意の画像に対するものである場合は、リダイレクトします。それ以外の場合はリダイレクトしません。
どんな助けでも大歓迎です!
編集:ここに役立つ完全なファイルがあります:
## Default .htaccess file
IndexIgnore *
Options +FollowSymlinks
RewriteEngine on
RewriteOptions MaxRedirects=10
# your rules were looping before, that's bad, this will stop it
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
# redirect the browser back to the referring page
RewriteCond %{REQUEST_URI} ^/img/
RewriteCond %{REQUEST_URI} \.(png|gif|jpe?g)$ [NC]
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?domain.com/
RewriteRule ^ %{HTTP_REFERER} [L,R]
# rewrite the request to the handler
RewriteCond %{REQUEST_URI} ^/img/
RewriteCond %{REQUEST_URI} \.(png|gif|jpe?g)$ [NC]
RewriteCond %{HTTP_REFERER} ^https?://(www\.)?domain.com/
RewriteRule ^(.*)$ /img/index.php?img_hash=$1 [L]
## Do pretty permalinks for our images
# these rules ensure you aren't clobbering legit requests (like to image.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# just in case, exclude the admin directory
RewriteCond %{REQUEST_URI} !^/admin [NC]
# rewrite
RewriteRule ^(.*)$ /display_image.php?img_hash=$1 [L]
ホットリンクを除いて、すべてが私が望むように正確に機能します:
domain.com/t4hd -> domain.com/display_image.php?img_hash=t4hd (WORKS)
domain.com/t4hd.jpg -> domain.com/display_image.php?img_hash=t4hd.jpg (WORKS)
domain.com/img/t4hd -> domain.com/img/index.php?img_hash=t4hd (WORKS)
domain.com/img/t4hd.jpg -> domain.com/img/index.php?img_hash=t4hd.jpg (WORKS)
domain.com/img/123/456/789/t4hd.jpg -> domain.com/img/index.php?img_hash=t4hd.jpg (DOES NOT WORK)
すべてのリクエストを次のように許可する必要があります。
domain.com/admin/index.php (WORKS)
domain.com/profile/index.php (WORKS)
うまくいけば、これは何が起こっているのかを明確にするのに役立ちます. 最初にこれをしなかったことをお詫びします。