.htaccess redirect to mobile site

I am trying to use a .htaccess redirect to redirect mobile phone users to a mobile site. The issue I am having is the redirect is working but it's applying it to all visits. Including PC users. Am I right to user the HTTP_USER_AGENT?  I only want mobile users to be redirected. Below is a copy of the contents of my .htaccess  can anyone see why it would redirect all users?

Thanks in advance


RewriteEngine on
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^www\.mysite\.com\.au\/Home\.html$ "http\:\/\/www\.mysite\.com\.au\/My_site\/Home\.html" [R=301,L]

RewriteCond %{HTTP_USER_AGENT} android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge\ |maemo|midp|mmp|opera\ m(ob|in)i|palm(\ os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows\ (ce|phone)|xda|xiino [NC,OR]
RewriteRule ^$ http://mymobilesite.com [R,L]

RewriteCond %{HTTP_HOST} ^mysite\.com\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mysite\.com\.au$
RewriteRule ^sa$ "http\:\/\/www\.mysite\.com\.au\/My_site\/SA\.html" [R=301,L]

RewriteCond %{HTTP_HOST} ^mysite\.com\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mysite\.com\.au$
RewriteRule ^SA$ "http\:\/\/www\.mysite\.com\.au\/My_site\/SA\.html" [R=301,L]

RewriteCond %{HTTP_HOST} ^mysite\.com\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mysite\.com\.au$
RewriteRule ^Home\.html\/?(.*)$ "http\:\/\/www\.mysite\.com\.au\/My_site\/Home\.html$1" [R=301,L]

RewriteCond %{HTTP_HOST} ^mysite\.com\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mysite\.com\.au$

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lucas BishopClick TrackerCommented:
I'd start by encasing the user agents in double quotes:
RewriteCond %{HTTP_USER_AGENT} "android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge\ |maemo|midp|mmp|opera\ m(ob|in)i|palm(\ os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows\ (ce|phone)|xda|xiino" [NC,OR]

Open in new window

I would also slim down this list and add only a few at a time.  Add 3, test. Add another 3 test, etc. For example:

RewriteCond %{HTTP_USER_AGENT} "android|avantgo|blackberry" [NC,OR]

Open in new window

There may be a specific user agent in there that shouldn't be part of the redirect. I'm not familiar with all mobile user-agents, so I can't visually tell if one specific agent is the problem.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MattyS82Author Commented:
Thanks Lucas. I will give this a go and I will let you know how it goes.
NerdsOfTechTechnology ScientistCommented:
Alternatively, so can use CSS to detect resolution opposed to the ZILLION of user-agents and spoofed agents and serve a responsive site (morphs from mobile to desktop and vise-versa just on resolution size).
MattyS82Author Commented:
Apologies for taking so long to get back to you. I have been away.

That's fantastic thanks for the assist.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.