I'm having some trouble getting the code statement beneath to work as intended. The first part of the code is all good. When a user hits example.com without 'www', he's being 301 redirected to www.example.com to protect the ingoing links.
At the same time I'm trying to use subdomains. If a user hits candybar.example.com I want the page test.php?subdomain=candybar to be loaded. Though this part doesn't seem to work, my users are being served the index page instead.
I hope someone has an idea what I'm doing wrong - thanks in advance!
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ test.php?subdomain=$1 [L]