1

I am looking for assistance with coding to detect and redirect a iOS user on any browser other than Safari. I was able to accomplish this via .htaccess, but for iPhone & iPad redirect only, via this:

RewriteCond %{HTTP_USER_AGENT} iphone|ipad [NC]
RewriteRule ^$ /ios.php

But, I only intend it for non-Safari iOS browsers on iPhone and iPad. Open to other methods than htaccess. Our WebRTC script only works on Safari.

psone
  • 95
  • 8
  • maybe fix your webrtc script? – Lukas Mittun Alexander Guldstv Mar 16 '21 at 16:39
  • @Heimdalssidstevogter It is an Apple limitation, not with our software. – psone Mar 16 '21 at 16:45
  • ahh. if you have a staging env of some kind you could print `$_SERVER["HTTP_USER_AGENT"];` or just print all `$_SERVER` and look for a tag that fits the requirements (if such exist) – Lukas Mittun Alexander Guldstv Mar 16 '21 at 16:48
  • @Heimdalssidstevogter Unfortunately, we don't. – psone Mar 16 '21 at 16:52
  • https://stackoverflow.com/a/14057883/10480423 try and add the safari tag after the first condition with a negation tag. – Lukas Mittun Alexander Guldstv Mar 16 '21 at 16:58
  • @Heimdalssidstevogter Thanks for the reply. Unfortunately that grabs desktop users of Safari as well. – psone Mar 16 '21 at 17:08
  • User-Agent strings are just about the worst way of detecting anything, and should be used only as a last resort, when you're 110% sure there is no other way. Since your actual problem is that some client-side code will not work with certain clients, you should make your check in client-side code, and make it check for the actual limitation that causes the problem. For instance, if those browsers are missing a particular JS function that you rely on, check for the existence of that function. – IMSoP Mar 16 '21 at 22:00

1 Answers1

1

If you have not found a solution, you can test this:

RewriteEngine on

RewriteCond %{HTTP_USER_AGENT} iphone|ipad [NC]
RewriteCond %{HTTP_USER_AGENT} Safari [NC]
RewriteCond %{HTTP_USER_AGENT} !(CriOS|OPiOS) [NC]
RewriteRule ^$ /safari-with-webrtc.php [L]

RewriteRule ^$ /ios-without-webrtc.php [L]

First we check if we are using iphone|ipad, the second directive detects safari. But chrome presents also with name safari, we exclude CriOS for Google Chrome and OPiOS for Opera, so we have True safari, we run /safari-with-webrtc.php.

Otherwise, we are not on iPhone|iPad with Safari, we run /ios-without-webrtc.php.

jacouh
  • 8,473
  • 5
  • 32
  • 43