.htaccess thumb php图片链接

I want to make better links to thumb image with php

my current image link to thumb

mydomain.tld/thumbimg/thumb.php?size=50x50&src=../data/filename.jpg

but I want in this form

mydomain.tld/thumbimg/50x50/filename.jpg

I tried with this htaccess code

RewriteEngine on
RewriteRule ^([a-zA-Z0-9]+|)/?$ thumb.php?size=$1&src=../data/$2
# Handle requests for "thumb.php"

Where the error and how to fix it?

UPDATE: I found the solution, this is code

RewriteEngine On
RewriteRule ^(.*)$ -
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/.]+)/([^/.]+)\.jpg$ thumb.php?size=$1&src=../data/$2.jpg [L]
RewriteRule ^([^/.]+)/([^/.]+)\.png$ thumb.php?size=$1&src=../data/$2.png [L]

Try below rule in your respective directory,

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+)/([\w-]+)\.jpg$ thumb.php?size=$1&src=../data/$2 [L]