0

Got problem with a gif that loses it's animation with the rewrites I'm doing.

RewriteRule ^journal/(.+)\.(jpeg|jpg|png|mp4|webm|ogv)$ app/uploads/journal/$1 [QSA,L]
RewriteRule ^journal/(.+)\.(gif)$ app/uploads/journal/$1 [QSA,L,T=image/gif]

For some reason it still serves with image/jpeg headers. Any ideas why?

Rewrite Log

INT
  • 121
  • 4
  • 1
    In the directory where you keep the files, do they have filenames ending with `.gif` and `.jpg`? Because you're stripping those out from the request. – Jenny D Oct 24 '14 at 09:39
  • @JennyD It could happen that both `.jpg` and `.gif` exist with the same filename in the same location, but not in this case. For reference `RewriteRule ^journal/(.+) app/uploads/journal/$1 [QSA,L]` works splendidly, but I need to be able to filter. – INT Oct 24 '14 at 09:50
  • With the rules in the question I can't working animation at /journal/animation.gif, but if I go to /app/uploads/journal/animation.gif it works just fine. – INT Oct 24 '14 at 09:51

1 Answers1

1

The problem is that when you add the second match, to catch the filename ending, you are forgetting to attach that match to the rewrite. The first parenthesis $1, which you're adding on the rewrite side, but that one no longer contains the .gif, .jpg etc because they are outside the parenthesis. Instead, they end up in $2.

So try rewriting the rules to

RewriteRule ^journal/(.+)\.(jpeg|jpg|png|mp4|webm|ogv)$ app/uploads/journal/$1.$2 [QSA,L]
RewriteRule ^journal/(.+)\.(gif)$ app/uploads/journal/$1.$2 [QSA,L,T=image/gif]
Jenny D
  • 27,358
  • 21
  • 74
  • 110