jtrupiano / rack-rewrite

A web server agnostic rack middleware for defining and applying rewrite rules. In many cases you can get away with Rack::Rewrite instead of writing Apache mod_rewrite rules.
http://github.com/jtrupiano/rack-rewrite
MIT License
836 stars 80 forks source link

301 rewrite not matching for one query #56

Closed dp6ai closed 10 years ago

dp6ai commented 10 years ago

Can any one tell me why this works:

r301 %r{(?:images\/)(\d*.jpe?g|png|gif)$}, 'http://mybucket.s3.amazonaws.com/540x310/$1'

URI = http://www.mysite.com/images/42720.jpeg

and this doesn't

r301 %r{(?:resized_images\/\dx\d\/)(\d*.jpe?g|png|gif)$}, 'http://mybucket.s3.amazonaws.com/540x310/$1'

URI = http://mysite.com/resized_images/560x344/77664.jpeg

Both work at Rubular: http://rubular.com/r/PXHiEcoEqy http://rubular.com/r/BfOta6YJa7

dp6ai commented 10 years ago

Has anyone seen anything like this before? The two redirects seem to be very similar, i cant understand why one is working but not the other?

thanks

dp6ai commented 10 years ago

Ok I have got a little further.

The rewrite isn't working with two 301 query strings.

if i comment out the first line the second works and vice versa. Any idea how to get them both working.

    use Rack::Rewrite do
        r301 %r{(?:images\/)(\d*.jpe?g|png|gif|bmp)$}, 'http://mybucket.s3.amazonaws.com/540x310/$1'
        r301 %r{(?:resized_images\/\d*x\d*\/)(\d*.jpe?g|png|gif|bmp)$}, 'http://mybucket.s3.amazonaws.com/540x310/$1'
     end
dp6ai commented 10 years ago

Obviously i needed to change $1 to $2 in the second line.

thanks and closing.

dp6ai commented 10 years ago

Sorry. End of the day and that isnt working can anyone point me in the right direction. thanks

dp6ai commented 10 years ago

final answer. I hope

I broke the second redirect out into another use Rack::rewrite and it fixed the issue