这篇关于loading files from a remote site when they don't exist locally的SO文章提供了.htaccess RewriteConds和RewriteRules来完成任务。
我也想在我的WordPress网站上使用它,所以我认为这些说明对我来说是完美的,但它们并不起作用。我正在使用在MAMP PRO 2.0上运行的WordPress 3.9.1
我将本地网站的URL构造为; local.domain.com
所以我将原始SO文章中的模式更改为以下
# Use remote uploads when they don't exist locally
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^local\.domain\.com$
RewriteRule ^.*/(uploads/.*)$ http://domain.com/wp-content/$1 [L,R=301,NC]
</IfModule>
最初的SO文章并不清楚应该放置此.htaccess文件的位置。我在WordPress根目录中尝试了它,而/ wp-content / uploads /没有成功。
任何有关我做错的想法都会受到赞赏。
答案 0 :(得分:2)
在/wp-content/uploads/.htaccess
中尝试此规则:
RewriteEngine On
RewriteBase /wp-content/uploads/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^local\.domain\.com$
RewriteRule ^(.+)$ http://domain.com/wp-content/uploads/$1 [L,R=301,NE]