与htaccess的的图像重定向到另一个服务器,而无需重定向循环 [英] Redirect with htaccess for images onto another server without redirect looping

查看:110
本文介绍了与htaccess的的图像重定向到另一个服务器,而无需重定向循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有在我的主网站托管在一台主机。我已成立了nginx的另一台服务器上,以反映正在请求/缓存文件,如果没有它了,尤其是图像和FLV视频。

例如:

www.domain.com是我的主网站。

www.domain.com/video/vi​​deo.flv

www.domain.com/images/1.png

我想问一下Apache将重定向到imgserv.domain.com(imgserv.domain.com点到另一台服务器IP)

imgserv.domain.com/video/vi​​deo.flv

imgserv.domain.com/images/1.png

基本上重定向一切与特定的文件类型和preserving 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
 

解决方案

正在混淆两个不同的模块: RewriteEngine叙述的RewriteCond mod_rewrite的 RedirectMatch mod_alias中。他们不能一起工作。

试试这个mod_rewrite的例子来代替:

  RewriteEngine叙述ON
的RewriteCond%{HTTP_HOST} ^ WWW \ .EXAMPLE \ .COM $ [NC]
重写规则^ * \。(GIF | JPG | PNG)$ http://imgserv.example.com/forums/$0 [L,R]
 

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

解决方案

You are mixing up two different modules: RewriteEngine and RewriteCond are from mod_rewrite while RedirectMatch is from mod_alias. They can’t work together.

Try this mod_rewrite example instead:

RewriteEngine ON
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^.*\.(gif|jpg|png)$ http://imgserv.example.com/forums/$0 [L,R]

这篇关于与htaccess的的图像重定向到另一个服务器,而无需重定向循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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