I am trying to redirect blackberry users to my mobile site by doing:
# redirect for blackberry users
RewriteCond %{HTTP_USER_AGENT} ^.BlackBerry.$
RewriteRule ^(.*)$ http://www.domain.com/m/ [R=301]
in my .htaccess, but nothing happens when I try to access from the device, I’ve already deleted cache and cookis and nothing works. I have been googling around and it seems I’m doing the redirect correctly but I guess not, what am I missing?
My .htaccess only contains that by the way.
Edit
The .htaccess in my server’s root.
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
Lflag.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:
You may also want that
RewriteRuleto be……if the content is named the same (but mobile-friendly) in the
/m/directory.