3

Quick search revealed many guides explaining how to detect an iPhone or iPad:

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} iPhone
RewriteRule .* http://iphone.example.com/ [R]

but is there any way to detect a Mac user (any browser), and redirect him?

Wooble
  • 87,717
  • 12
  • 108
  • 131
eozzy
  • 66,048
  • 104
  • 272
  • 428

1 Answers1

7

Macintosh UserAgents looks like something like this : Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7

As far as I know, RewriteCond %{HTTP_USER_AGENT} will look for the regular expression you gave him. In the mentioned case, if he finds iPhone in the User-Agent, the condition test will return true. So it should be possible to do something like this :

RewriteCond %{HTTP_USER_AGENT} Macintosh
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^ http://mac.example.com%{REQUEST_URI} [R]

Hope this works, and hope this helps :)

rayfranco
  • 3,630
  • 3
  • 26
  • 38
  • There is a related question: http://stackoverflow.com/questions/228256/operating-system-from-user-agent-http-header – St.Woland Mar 12 '12 at 16:18
  • This is probably due to your RewriteRule. I've been testing the updated rule in my answer on my localhost and it works perfectly. Make sur your RewriteRule will works first, then add the RewriteCond. In my snippet, I am redirecting ALL users on a Mac that are trying to browse my www website to a mac subdomain. You also could redirect the download.html to a download-mac.html or something... But this seems a little bit instrusive. What is your specific use case of this ? – rayfranco Mar 13 '12 at 10:31
  • This will not work because you are first redirecting `www.domain.com` or `mac.domain.com` to `domain.com` (line 5) and so, you'll never be able to catch `www.domain.com` as you are trying to do on line 16. Can you give me the real `.htaccess` you are trying to use ? Also make sure you have a host routing for "*.domain.com" if you are working in local with that fake domain name. A quick fix to test this question, is to remove line 4 and line 5. – rayfranco Mar 13 '12 at 17:50
  • That is the htaccess I'm using. Btw, removing those lines and adding yours makes it go in a redirection loop. – eozzy Mar 18 '12 at 11:57