Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2016
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    [.htaccess] Block all USER_AGENT except a custom one

    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

    Code:
    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:

    Code:
    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!

  2. #2
    Regular Coder
    Join Date
    Jun 2008
    Posts
    316
    Thanks
    4
    Thanked 27 Times in 27 Posts
    To my knowledge there is now way to set rewrite conditions for User Agent. But maybe im wrong.
    Why don't you use PHP to check for user agent?
    PHP Code:
    <?php
    if(strstr($_SERVER['HTTP_USER_AGENT'],'MyAPP')){
        echo 
    'You are okay';
    }else{
        echo 
    'Denied';
    }
    ?>
    Last edited by Labrar; 07-15-2017 at 07:56 PM.
    I never ever read PM's unless it's an job offer. So save your time for regular questions in the forum. I never ever take friendship offers. We are not on facebook here.(It's stupid on facebook too). Friendship? Do i know you? Did we ever had a beer together? Thats really stupid. Sorry.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •