.htaccess allow only from Chrome, Opera, Mozilla,

2019-07-23 04:51发布

问题:

I want to configure redirect if the user doesn't use Chrome, Safari, Opera or Mozilla.

For inverse problem (if I don't want Chrome etc.) there is a solution:

RewriteCond %{HTTP_USER_AGENT} Chrome
RewriteRule ^abcd.html$ chrome.html [NC,L]

RewriteCond %{HTTP_USER_AGENT} Safari
RewriteRule ^abcd.html$ safari.html [NC,L]

Adding ! before doesn't work

回答1:

Negation is done using the ! operator. Using the [NC] flag will also discard strings like chrome, chRome etc:

RewriteCond %{HTTP_USER_AGENT} !Chrome [NC]
RewriteRule ^abcd.html$ chrome.html [NC,L]