Jump to content

Howto Block all USER_AGENT except a custom one


roger01

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.