htaccess 将所有图像重定向到不同的位置并将图像名称放入新的 url 中
这是我正在使用的重写规则:
RewriteRule (.*\.(jpe?g|gif|bmp|png))$ http://www.newurl.com/?image=$1
我想要的是将所有图像重定向到新位置,并且上述规则部分有效。问题是 $1 将包含旧请求的整个 url,而不仅仅是文件名。我只需要文件名,但我尝试的所有内容似乎都无法正常工作。任何帮助表示赞赏。
我想我已经明白了。如果有人有任何其他解决方案,请随时添加。谢谢。
RewriteRule ^([^.]+)/([^.]+\.(jpe?g|gif|bmp|png))$ http://www.newurl.com/$2
谢谢。
This is the rewrite rule that I am working with:
RewriteRule (.*\.(jpe?g|gif|bmp|png))$ http://www.newurl.com/?image=$1
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
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上这个规则对你来说会更好:
最好只匹配图像名称而不是完整的 REQUEST_URI,从而删除文本字符的开头
^
R 标志文档
Actually this rule will be better for you:
It is better to match just the image name rather than full REQUEST_URI thus removal of start of text character
^
R Flag documentation