开发者

mod_rewrite per-dir redirection returning a 400

I moved my images directory to a different folder, and now I want to redirect all images requests from that folder to the new one. I do not have access to the main configuraion file, so I'm doing this in a .htaccess.

I tried this, and it works:

RewriteCond %{REQUEST_URI} old_dir/.+\.(jpg|png|gif)$

RewriteRule old_dir/(.+[^/]+\..+)$ $1 [L,PT]

But since they have permanently moved, I want to do a proper redirect, so I added the [R] flag, like this:

RewriteCond %{REQUEST_URI} old_dir/.+\.(jpg|png|gif)$

RewriteRule old_dir/(.+[^/]+\..+)$ $1 [L,PT,R]

But the server gets confused, and returns a 400, so I looked at the log file, and this is what ha开发者_如何学JAVAppens:

strip per-dir prefix: C:/wamp/www/natrazyle/old_dir/images/banner.jpg -> old_dir/images/banner.jpg

applying pattern 'old_dir/(.+[^/]+\..+)$' to uri 'old_dir/images/banner.jpg'

rewrite 'old_dir/images/banner.jpg' -> 'images/banner.jpg'

add per-dir prefix: images/banner.jpg -> C:/wamp/www/natrazyle/images/banner.jpg

explicitly forcing redirect with http://localhost/C:/wamp/www/natrazyle/images/banner.jpg

As you can see, the full local path gets added after localhost

I know I'm doing something wrong, I just can't figure it out myself. Any help would be greatly appreciated...


Use an absolute URL path in your substitution:

RewriteRule ^old_dir/(.+\.(jpg|png|gif))$ /$1 [L,R]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜