我正在尝试在.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
有人可以帮忙吗?
答案 0 :(得分:1)
以这种方式修改你的规则:
RewriteRule /([^./]+\.(jpg))$ http://www.example1.com/img/gallery/$1
最后一次斜线后只需要文件名。