roger01 Posted June 4, 2017 Share Posted June 4, 2017 Hello, I'm trying to have a web page accessible only from inside an android app. I can make the app to provide a custom user agent. For example Mozilla/5.0 (MyAPP) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36 I need to edit the .htaccess file to deny all visitors, except the one with the "MyAPP" string in its user agent.I've tried using this: RewriteCond %{HTTP_USER_AGENT} ^.*MyAPP*$ RewriteRule .* - [L] RewriteRule .* http://mydomain.com/error.html [R,L] but i get all traffic sent to error.html, including the one from my app.What am I missing here?Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/304067-howto-block-all-user_agent-except-a-custom-one/ Share on other sites More sharing options...
dalecosp Posted June 5, 2017 Share Posted June 5, 2017 You've verified that the UA string being sent is indeed correct? Quote Link to comment https://forums.phpfreaks.com/topic/304067-howto-block-all-user_agent-except-a-custom-one/#findComment-1547082 Share on other sites More sharing options...
dalecosp Posted June 5, 2017 Share Posted June 5, 2017 With further thought, try commenting the 2nd line out? It appears (I'm not an HTACCESS expert) to me that your 3rd rule is applying to all cases because the 2nd one if being assigned to the RewriteCond class.... Quote Link to comment https://forums.phpfreaks.com/topic/304067-howto-block-all-user_agent-except-a-custom-one/#findComment-1547083 Share on other sites More sharing options...
jay5r Posted June 5, 2017 Share Posted June 5, 2017 I'd try this… RewriteCond %{HTTP_USER_AGENT} !MyApp RewriteRule ^.* http://mydomain.com/error.html [R=302] I think the most critical thing you were missing was the ! at the beginning of the pattern. That ! says "not"… You were matching the string, you needed to match all the ones that don't match the string. I think L is redundant if there's a redirect. And I always do R=302 (or R=301) so I know exactly what type of redirect is being done. Quote Link to comment https://forums.phpfreaks.com/topic/304067-howto-block-all-user_agent-except-a-custom-one/#findComment-1547086 Share on other sites More sharing options...
requinix Posted June 5, 2017 Share Posted June 5, 2017 ^.*MyAPP*$Typo. Quote Link to comment https://forums.phpfreaks.com/topic/304067-howto-block-all-user_agent-except-a-custom-one/#findComment-1547087 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.