使用 htaccess 将图像重定向到另一台服务器,无需重定向循环

发布于 2024-09-06 00:09:52 字数 774 浏览 2 评论 0原文

我目前有一个托管我的主站点的主机。我已经在另一台服务器上设置了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风情万种。 2024-09-13 00:09:52

您混合了两个不同的模块:RewriteEngineRewriteCond 来自 mod_rewriteRedirectMatch 来自 mod_alias。他们不能一起工作。

试试这个 mod_rewrite 示例:

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

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]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文