Q:

Redirecting dynamic(variable) subdomain to a controller using .htaccess

I am trying to create a user page url of the form user1.mydomain.com , and I need it to redirect to http://mydomain.com/index.php/users/index/user1 .  
In my .htaccess file, I have the following:
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.com$
RewriteRule (.*)  http://mydomain.com/index.php/users/index/$1 [L]

I am getting "this webpage is not available" from google chrome, at least not a server error. 
What am I doing wrong?  Also, in the rewriterule pattern, how does it know that $1 refers to the subdomain and not the full url?  Is it because I have %{HTTP_HOST} in my rewritecond ? 

A:

Captured variables from RewriteCond are denoted as %1, %2 etc...
Try this rule:
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC]
RewriteRule ^ http://mydomain.com/index.php/users/index/%1 [L,R]

