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

Jam*_*s T 8 apache .htaccess mod-rewrite redirect

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

例:

如果您要求,http://example.com/potato.png那么它将重定向到http://anotherdomain.com/potato.png.

Boo*_*eus 15

这是使用jpg,gif或png扩展名将图像重定向到anotherdomain.com的快速解决方案

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

  • 为什么 - 我最好留下@BookOfZeus来纠正他的答案(他在你做出更正之前回答**) - 他应该很容易想出一个不同的工作解决方案(提示:捕获全名并使用`$ 1` ) - 我有足够的代表;)@ Bubby4j - 你可以自由使用任何变种:) (2认同)