Hi

I want to accomplish the following:
redirect non-www to www for all users
redirect desktop users to www.example.com/homepage
redirect mobile users to www.example.com/m

Here is my htaccess code. The problem is, if I am on an iphone and I type www.exampole.com it DOES direct to /m BUT if I dont put www at the beginning, it says too many redirects and the page doesn't open. I really dont know what I'm doing, please help.

Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ /homepage/ [R=301]
</IfModule>

RewriteCond %{HTTP_USER_AGENT} ^.*iPad.*$
RewriteRule ^(.*)$ http://www.example.com/m [R=301]
RewriteCond %{HTTP_USER_AGENT} ^.*iPod.*$
RewriteRule ^(.*)$ http://www.example.com/m [R=301]
RewriteCond %{HTTP_USER_AGENT} ^.*iPhone.*$
RewriteRule ^(.*)$ http://www.example.com/m [R=301]
RewriteCond %{HTTP_USER_AGENT} ^.*iemobile.*$
RewriteRule ^(.*)$ http://www.example.com/m [R=301]
RewriteCond %{HTTP_USER_AGENT} ^.*blackberry.*$
RewriteRule ^(.*)$ http://www.example.com/m [R=301]
RewriteCond %{HTTP_USER_AGENT} ^.*Android.*$
RewriteRule ^(.*)$ http://www.example.com/m [R=301]