views:

28

answers:

1

Hey guys,

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
A: 

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]
Gumbo
Hi Gumbo, thanks for the reply. I have placed it in my root public_html directory however any files in the folder (example.com/picture.jpg) redirects as example.com/forums/forums/forums... /picture.jpg)It also doesn't redirect any images in further directories, could you help?
Jeff
@Jeff: Use this additional condition to skip requests that’s path does already start with `/forum/`: `RewriteCond $0 !^forums/`.
Gumbo