htaccess的,从暂存URL加载资源时,文件不存在本地不存在、加载、文件、资源

2023-09-02 00:56:57 作者:初心如梦i

我想从一个临时网站加载图像,如果他们没有本地存在。 这基本上是有用的,所以我没有继续下载所有图像上的临时网站的客户端上传。目前,我有什么是工作,但它是一个全有或全无的解决方案。因此,所有的图像远程加载,但我想htaccess的只加载远程图片,如果一个地方不存在。

I'm trying to load images from a staging site if they don't exist locally. This is basically useful so I don't have to keep downloading all the images that the client uploads on the staging site. At the moment, what I have is working, but it's an all-or-nothing solution. So, all the images are loading remotely but I'd like htaccess to only load remote images if a local one doesn't exist.

下面是我有:

的RewriteCond%{HTTP_HOST} ^本地网站 .dev $ 重写规则^ * /上传/(.*)$ http://remote-site.com/wp-content/uploads/$1 [L,R = 301]

RewriteCond %{HTTP_HOST} ^local-site.dev$ RewriteRule ^.*/uploads/(.*)$ http://remote-site.com/wp-content/uploads/$1 [L,R=301]

在此先感谢。

推荐答案

更​​改您的规则如下:

Change your rule to this:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^local-site.dev$
RewriteRule ^.*/(uploads/.*)$ http://remote-site.com/wp-content/$1 [L,R=301,NC]

下面的RewriteCond%{} REQUEST_FILENAME!-f 将确保这种重定向只发生在图像文件于本地存在。

Here RewriteCond %{REQUEST_FILENAME} !-f will make sure that this redirection happens only when image file doesn't exist locally.

 
精彩推荐
图片推荐