图片防盗链及网页跳转
Hotlink protection for images and redirect to webpage
我生成了 .htaccess 规则,该规则将请求图像从或来源重定向到包含该图像的网页。但是,它不起作用,显然我做错了什么。任何想法表示赞赏!
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/manufacturers///.jpg
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?example.com [NC]
RewriteRule (.*) http://www.example.com//
请求示例:www.example.com/manufacturers/audi/audi-a8/audi-a8-1.jpg
应该重定向到:www.example.com/audi/audi-a8/
这一行有问题:
RewriteCond %{REQUEST_URI} ^/manufacturers///.jpg
因为 </code>、<code>
等在 RewriteCond
的 RHS 上不可用。您可以改用此规则:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?example\.com [NC]
RewriteRule ^manufacturers/([^/]+)/[^/]+/([^/]+)/[^/.]+\.jpe?g$ // [L,NC,R=302]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?example\.com [NC]
RewriteRule ^manufacturers/([^/]+/[^/]+)/[^/.]+\.jpe?g$ / [L,NC,R=302]
我生成了 .htaccess 规则,该规则将请求图像从或来源重定向到包含该图像的网页。但是,它不起作用,显然我做错了什么。任何想法表示赞赏!
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/manufacturers///.jpg
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?example.com [NC]
RewriteRule (.*) http://www.example.com//
请求示例:www.example.com/manufacturers/audi/audi-a8/audi-a8-1.jpg
应该重定向到:www.example.com/audi/audi-a8/
这一行有问题:
RewriteCond %{REQUEST_URI} ^/manufacturers///.jpg
因为 </code>、<code>
等在 RewriteCond
的 RHS 上不可用。您可以改用此规则:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?example\.com [NC]
RewriteRule ^manufacturers/([^/]+)/[^/]+/([^/]+)/[^/.]+\.jpe?g$ // [L,NC,R=302]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?example\.com [NC]
RewriteRule ^manufacturers/([^/]+/[^/]+)/[^/.]+\.jpe?g$ / [L,NC,R=302]