使用 htaccess 将图像重定向到另一台服务器,无需重定向循环
我目前有一个托管我的主站点的主机。我已经在另一台服务器上设置了 nginx,以镜像/缓存所请求的文件(如果还没有),特别是图像和 flv 视频。
例如:
www.domain.com 是我的主站点。
www.domain.com/video/video.flv
www.domain.com/images/1.png
我想请apache将其重定向到imgserv.domain.com(imgserv.domain.com指向另一个服务器IP)
imgserv .domain.com/video/video.flv
imgserv.domain.com/images/1.png
基本上重定向具有某些文件类型的所有内容并保留 URL 的结构,例如 flv 等。
我尝试了一些方法,但出现了重定向循环错误。有人可以帮我吗?
谢谢你!
这就是我现在所拥有的
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RedirectMatch 302 ^(.*)\.gif$ http://imgserv.domain.com/forums$1.gif
RedirectMatch 302 ^(.*)\.jpg$ http://imgserv.domain.com/forums$1.jpg
RedirectMatch 302 ^(.*)\.png$ http://imgserv.domain.com/forums$1.png
I currently have a host where my main site is hosted on. I have set up nginx on another server to mirror/cache files being requested if it doesn't have it already, in particular images and flv videos.
For example:
www.domain.com is my main site.
www.domain.com/video/video.flv
www.domain.com/images/1.png
I would like to ask apache to redirect it to imgserv.domain.com (imgserv.domain.com points to another server IP)
imgserv.domain.com/video/video.flv
imgserv.domain.com/images/1.png
Basically redirect everything with certain filetypes and preserving the structure of the URL, like flv etc.
I tried something but I am getting a redirect looping error. Could someone help me out?
Thank you!
This is what I have at the moment
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RedirectMatch 302 ^(.*)\.gif$ http://imgserv.domain.com/forums$1.gif
RedirectMatch 302 ^(.*)\.jpg$ http://imgserv.domain.com/forums$1.jpg
RedirectMatch 302 ^(.*)\.png$ http://imgserv.domain.com/forums$1.png
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您混合了两个不同的模块:
RewriteEngine
和RewriteCond
来自 mod_rewrite 而RedirectMatch
来自 mod_alias。他们不能一起工作。试试这个 mod_rewrite 示例:
You are mixing up two different modules:
RewriteEngine
andRewriteCond
are from mod_rewrite whileRedirectMatch
is from mod_alias. They can’t work together.Try this mod_rewrite example instead: