0

I am currently using this in my .htaccess:

RewriteCond %{HTTP_USER_AGENT} Chrome
RewriteRule .* - [L]
RewriteRule .* URL [R,L]

It work in Windows and Android . But not in Ios . I try

RewriteCond %{HTTP_USER_AGENT} Chrome|Crios

Still won't work. Anyone please help me .

  • Hi Jackern Jack. I have provided the working solution along with a regex tester for your question. In case of any issue, do comment or if that solves your problem up vote and accept the answer so that other SO users can benefit from the same – Ankit Rastogi Oct 22 '18 at 13:19

1 Answers1

1

As mentioned in the official documentation of Google chrome browser link, it uses either

Chrome or CriOS (for iOS)

in user agent header. So you need to check for both in case you wanted to test for chrome browser

The rule for it can be following

RewriteCond %{HTTP_USER_AGENT} ^.*(Chrome|CriOS).*$
RewriteRule .* - [L]
RewriteRule .* URL [R,L]

The regex is working and can be verified at regex tester

However there is no single approach through which you can be sure that the browser is official Chrome because many other browsers are also using chrome in their user agent header to ride the popularity of Google Chrome like

Dragon,Edge,Flock,Iron,Kinza,Maxthon (to name a few)

You can go to http://www.useragentstring.com/ to find the user agents of other browsers that uses chrome in their user agent header and exclude them in the rewrite rule.

So the final rewrite rule can be following

RewriteCond %{HTTP_USER_AGENT} ^.*(Chrome|CriOS).*$
RewriteCond %{HTTP_USER_AGENT} !^.*(Aviator|ChromePlus|coc_|Dragon|Edge|Flock|Iron|Kinza|Maxthon|MxNitro|Nichrome|OPR|Perk|Rockmelt|Seznam|Sleipnir|Spark|UBrowser|Vivaldi|WebExplorer|YaBrowser).*$
RewriteRule .* - [L]
RewriteRule .* URL [R,L]

The browser list is from link

Ankit Rastogi
  • 597
  • 4
  • 14