.htaccess重写规则 - 将任何请求的jpg的url更改为转到另一台服务器

时间:2015-05-21 11:33:46

标签: apache .htaccess mod-rewrite redirect

我正在尝试在.htaccess中为特定文件夹及其子文件夹设置重写规则,以便将对jpg图像文件的任何请求重定向到另一个域。问题是路径也被重定向,我不想发生。

示例 - 我需要

http://www.example.com/test/media/0/1/test.jpg被定向到 http://www.example1.com/img/gallery/test.jpg

http://www.example.com/test/media/5/7/test1.jpg被定向到 http://www.example1.com/img/gallery/test1.jpg

我在../test/media文件夹中创建了一个.htaccess文件,目前我在那里

RewriteEngine on
RewriteCond %{HTTPS} !on
RewriteRule ([^.]+\.(jpg))$ http://www.example1.com/img/gallery/$1

请求被重定向,但它被重定向到

http://www.example1.com/img/gallery/0/1/test.jpg

当我需要它时

http://www.example1.com/img/gallery/test.jpg

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

以这种方式修改你的规则:

RewriteRule /([^./]+\.(jpg))$ http://www.example1.com/img/gallery/$1

最后一次斜线后只需要文件名。