Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Mac users - htaccess

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?

like image 273
eozzy Avatar asked Nov 26 '25 10:11

eozzy


1 Answers

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 :)

like image 122
rayfranco Avatar answered Nov 29 '25 00:11

rayfranco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!