htaccess的,从暂存URL加载资源时,文件不存在本地 [英] htaccess to load assets from staging URL when file doesn't exist locally

查看:138
本文介绍了htaccess的,从暂存URL加载资源时,文件不存在本地的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这篇关于htaccess的,从暂存URL加载资源时,文件不存在本地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆