Apache mod_rewrite将文件类型重定向到另一个域

Apache mod_rewrite将文件类型重定向到另一个域,apache,.htaccess,mod-rewrite,redirect,Apache,.htaccess,Mod Rewrite,Redirect,如何使用mod_rewrite将特定文件类型的请求发送到另一个域名(服务器) 示例: 如果您请求http://example.com/potato.png然后它将重定向到http://anotherdomain.com/potato.png这里有一个快速解决方案,可以将带有jpg、gif或png扩展名的图像重定向到anotherdomain.com RewriteEngine on RewriteRule \.(gif|jpg|png)$ http://anotherdomain.com/%{R

如何使用mod_rewrite将特定文件类型的请求发送到另一个域名(服务器)

示例:


如果您请求
http://example.com/potato.png
然后它将重定向到
http://anotherdomain.com/potato.png

这里有一个快速解决方案,可以将带有jpg、gif或png扩展名的图像重定向到anotherdomain.com

RewriteEngine on
RewriteRule \.(gif|jpg|png)$ http://anotherdomain.com/%{REQUEST_URI} [NC,R=301,L]   

不完全是我的意思,例如:如果你请求domain.com/potato.png,它将请求domain2.com/potato。png@BookOfZeus你就快到了。我会这样做(可能的解决方案之一):
RewriteRule\(gif | jpg | png)$http://anotherdomain.com%{REQUEST_URI}[NC,R=301,L]
为什么——我最好让@BookOfZeus来纠正他的答案(他在你纠正之前就回答了)——他应该很容易想出一个不同的工作解决方案(提示:获取全名并使用
$1
)--我有足够的代表;@Bubby4j--您可以自由使用任何变体:)@BookOfZeus我遇到了您的一个旧答案,我对这里的mod_rewrite有点问题,希望您能帮助我。我真的很感谢你的帮助,谢谢。最好的回答是