Mod ReWrite Catch-All Subdomain
Refer to this StackOverflow question: "Create Subdomains on the Fly With .htaccess"
See answers on the question, specifically this link which has examples which should work in your situation.
There are a couple of issues that the Webmasterworld post addresses, including subdomain recursion since the .htaccess also impacts your subdirectories in your main www root.
The final code is like so:
RewriteBase /
#### URL Rewrite Handler for Subdomains (by Randall Krause) ####
RewriteCond %{ENV:REDIRECT_SUBDOMAIN} =""
RewriteCond %{HTTP_HOST} ^([a-z0-9][-a-z0-9]+)\.mydomain\.org\.?(:80)?$ [NC]
RewriteCond %{DOCUMENT_ROOT}/subdomains/%1 -d
RewriteRule ^(.*) subdomains/%1/$1 [E=SUBDOMAIN:%1,L]
RewriteRule ^ - [E=SUBDOMAIN:%{ENV:REDIRECT_SUBDOMAIN},L]
If you want to see what your above code errors out on (what is creating the 500 error), check your error_log. My guess is that it is causing recursion.