开发者

htaccess redirect all images to different location and put image name in new url

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 pro开发者_StackOverflow社区perly. 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.


Actually this rule will be better for you:

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

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

R Flag documentation

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜