If this isn't the only rule in your .htaccess file, you might have an issue where a later rule messes up your redirect. To redirect immediately, you need to include the L
flag.
I also suspect that your regular expression for the user agent is probably not correct for the input you're testing against, since the two .
match just one character on either side of the word "BlackBerry". It would also be a good idea to guard against a redirect loop with a check to see if you're already in /m/
(although if you have mod_rewrite directives in a .htaccess file in that directory it's not important).
Putting all of that together, we get something like the following:
# Check for x-wap-profile/Profile headers
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile} !^$ [OR]
# Check for BlackBerry anywhere in the user agent string
RewriteCond %{HTTP_USER_AGENT} BlackBerry [NC]
# Make sure we're not in /m/ already
RewriteCond %{REQUEST_URI} !^/m/
RewriteRule ^ http://example.com/m/ [R=301,L]
You may also want that RewriteRule
to be...
RewriteRule ^.*$ http://example.com/m/$0 [R=301,L]
...if the content is named the same (but mobile-friendly) in the /m/
directory.