如何有选择地使用haccess加载外部图像


How To Selectively Load External Images Using Htacess

我想按照一定的规则加载除3张外的所有图片。剩下的3个应该从默认图像加载。

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !image_1.jpg$ [OR]
RewriteCond %{REQUEST_URI} !image_2.jpg$ [OR]
RewriteCond %{REQUEST_URI} !image_3.jpg$ [OR]
RewriteRule ^images/(.*)$ http://external-site.com/$1 [R,L]

Else -如果{REQUEST_URI}包含image_1.jpg或image_2.jpg或image_1.jpg则加载图像从我们说http://mydomain.com/default_image.jpg

你可以试试:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !(image_1|image_2|image_3)'.jpg   [NC]
RewriteRule ^images/(.*) http://external-site.com/$1 [R=301,L,NC]
RewriteCond %{REQUEST_URI} (image_1|image_2|image_3)'.jpg [NC]
RewriteRule .*             /default_image.jpg        [R=301,L]