Rewrite Query String

Posted by Virgil on Stack Overflow See other posts from Stack Overflow or by Virgil
Published on 2010-03-26T16:53:03Z Indexed on 2010/03/26 16:53 UTC
Read the original article Hit count: 343

Filed under:
|
|

Hello,

I am trying to write some mod_rewrite rules to generate thumbnails on the fly. So when this url

example.com/media/myphoto.jpg?width=100&height=100

the script should rewrite it to

example.com/media/myphoto-100x100.jpg

and if the file exists on the disk it gets served by Apache and if it doesn't exist it is called a script to generate the file.

I wrote this

RewriteCond %{QUERY_STRING}                              ^width=(\d+)&height=(\d+)
RewriteRule ^media/([a-zA-Z0-9_\-]+)\.([a-zA-Z0-9]+)$    media/$1-%1x%2.$2   [L]
RewriteCond %{QUERY_STRING}                              ^(.+)?
RewriteRule ^media/([a-zA-Z0-9_\-\._]+)$                 media/index.php?file=$1&%1 [L]

and I get infinite internal redirects. The first condition is matched and the rule is executed and right after that I get an internal redirect.

I need advice to finish this script.

Thank you.

© Stack Overflow or respective owner

Related posts about mod-rewrite

Related posts about thumbnail