htaccess将所有图像重定向到其他位置,并将图像名称放在新的url中 [英] htaccess redirect all images to different location and put image name in new url

查看:36
本文介绍了htaccess将所有图像重定向到其他位置,并将图像名称放在新的url中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我正在使用的重写规则:

This is the rewrite rule that I am working with:

RewriteRule (.*\.(jpe?g|gif|bmp|png))$ http://www.newurl.com/?image=$1

我想要的是所有图像都重定向到新位置,并且上述规则是偶发的.问题在于$ 1将包含旧请求中的整个URL,而不仅仅是文件名.我只需要文件名,而我尝试的所有内容似乎都无法正常运行.感谢您的帮助.

What I want is all images to get redirected to the new location and this above rule works paritally. The problem is that $1 will contain the whole url from the old request and not just the filename. I only need the filename and everything that I try doesnt seem to work properly. Any help is appreciated.

我想我已经知道了.如果还有其他解决方案,请不要犹豫地添加它们.谢谢.

I think i've figured it out. If anyone has any other solutions though, please don't hesitate to add them. Thanks.

RewriteRule ^([^.]+)/([^.]+\.(jpe?g|gif|bmp|png))$ http://www.newurl.com/$2

谢谢.

推荐答案

实际上,此规则对您而言更好:

Actually this rule will be better for you:

RewriteRule ([^.]+\.(jpe?g|gif|bmp|png))$ http://www.newurl.com/$1 [R=301,L,NC]

最好只匹配图像名称,而不要匹配完整的REQUEST_URI,这样可以删除文本字符^

It is better to match just the image name rather than full REQUEST_URI thus removal of start of text character ^

R标志文档

这篇关于htaccess将所有图像重定向到其他位置,并将图像名称放在新的url中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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