$10 via PayPal - How can I block these User Agents in htaccess?

Discussion in 'Apache' started by EducationLinks, Sep 10, 2008.

  1. #1
    Hello,

    I will PayPal $10 to the first person who provides the correct solution. (I will insert your code into my .htaccess file to confirm that it works.)

    I am on a Linux server. It's a shared server, but I do have a dedicated IP.

    In my .htaccess file, I need to block the following two user agents EXACTLY:

    -----------------------------

    Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1

    Opera/9.02 (Windows NT 5.1; U; ru)

    -----------------------------

    I don't want to block innocent visitors by making the blocks too general. Therefore, I need to block each exact, entire string (including all the stuff inside the parentheses).

    Thank you
     
    EducationLinks, Sep 10, 2008 IP
  2. cenourinha

    cenourinha Peon

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this:

       # good bye
       RewriteEngine on
       RewriteCond %{HTTP_USER_AGENT} ^Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1 [OR]
       RewriteCond %{HTTP_USER_AGENT} ^Opera/9.02 (Windows NT 5.1; U; ru)
       RewriteRule ^(.*)$ http://www.google.com
    
    Code (markup):
     
    cenourinha, Sep 11, 2008 IP
  3. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #3
    That won't work.

    Please try:
    RewriteEngine  on
    RewriteCond %{HTTP_USER_AGENT} ^Opera/9.02\ \(Windows\ NT\ 5.1;\ U;\ ru\)$ [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Mozilla/5.0\ \(Windows;\ U;\ Windows\ NT\ 5.1;\ ru;\ rv:1.8.1.1\)\ Gecko/20061204\ Firefox/2.0.0.1$
    RewriteRule ^.*$ deny.html [L]
    Code (markup):
    Jay
     
    jayshah, Sep 11, 2008 IP
  4. EducationLinks

    EducationLinks Well-Known Member

    Messages:
    1,193
    Likes Received:
    84
    Best Answers:
    0
    Trophy Points:
    140
    #4
    Jayshah,

    Don't you have to escape the periods? I'm not sure, but I think I read that somewhere online.
     
    EducationLinks, Sep 11, 2008 IP
  5. EducationLinks

    EducationLinks Well-Known Member

    Messages:
    1,193
    Likes Received:
    84
    Best Answers:
    0
    Trophy Points:
    140
    #5
    I tried both codes and they resulted in a 500 error.

    The prize is now $50!
     
    EducationLinks, Sep 11, 2008 IP
  6. mivent

    mivent Peon

    Messages:
    37
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    This works:

    RewriteEngine on
    RewriteCond %{HTTP_USER_AGENT} ^Opera/9.02\ \(Windows\ NT\ 5.1;\ U;\ ru\)$ [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Mozilla/5.0\ \(Windows;\ U;\ Windows\ NT\ 5.1;\ ru;\ rv:1.8.1.1\)\ Gecko/20061204\ Firefox/2.0.0.1$ [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Mozilla/4.0\ \(compatible;\ MSIE\ 7.0;\ Windows\ NT\ 6.0;\ WOW64;\ SLCC1;\ .NET\ CLR\ 2.0.50727;\ .NET\ CLR\ 3.0.04506;\ .NET\ CLR\ 1.1.4322\)$
    RewriteRule ^.*$ deny.html [L]


    (I added the last one just to test - this works on my server and blocks like it's supposed to.)

    If you put these in and it still does not work, it's likely that there is something else in your file causing the 500 error, not these lines specifically. Are you copying and pasting them in? If so, it could be a problem with line feeds that you are pasting in..... Maybe try just typing them in instead.
     
    mivent, Sep 11, 2008 IP
    EducationLinks likes this.
  7. CarcaBot

    CarcaBot Active Member

    Messages:
    389
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #7
    Try this :
    
    <IfModule mod_rewrite.c>
    RewriteCond %{HTTP_USER_AGENT} ^Opera/9.02 (Windows NT 5.1; U; ru) [OR]
    RewriteCond %{HTTP_USER_AGENT} ^Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1
    RewriteRule ^.* - [F,L]
    </IfModule>
    
    Code (markup):
    If u still geting 500 error. then u shold do this:
       1.  Edit the file /etc/sysconfig/apache2 as root:
             1. search for APACHE_MODULES, you should find a line like this
                APACHE_MODULES="suexec access actions alias auth auth_dbm autoindex cgi dir env expires include log_config mime negotiation setenvif userdir ssl php4"
             2. Add rewrite to the content in the list between the "
             3. Save the changes and quit
       2. run SuSEconfig to update the apache configuration files
       3. run /etc/init.d/apache2 restart to restart the Apache server
    Code (markup):
     
    CarcaBot, Sep 11, 2008 IP
    EducationLinks likes this.
  8. Dondon2d

    Dondon2d Peon

    Messages:
    3,193
    Likes Received:
    146
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I don't think he could do that on a shared server.
     
    Dondon2d, Sep 11, 2008 IP
    mentos likes this.
  9. EducationLinks

    EducationLinks Well-Known Member

    Messages:
    1,193
    Likes Received:
    84
    Best Answers:
    0
    Trophy Points:
    140
    #9
    A friend of a friend, who happens to be a database admin for a big company, actually came to my house and fixed the problem because I was in a panic. We went out to celebrate afterwards. Just got back.

    Mivent, I just tested your code by putting it in place of my friend's code. It does appear to work. I appreciate your effort! Therefore, I would like to send you something via PayPal, anyway.

    Sicario, thank you for your efforts, as well.
     
    EducationLinks, Sep 11, 2008 IP
  10. mentos

    mentos Prominent Member

    Messages:
    15,280
    Likes Received:
    473
    Best Answers:
    0
    Trophy Points:
    330
    #10
    You should have the IP of the person then only you can block it
     
    mentos, Sep 13, 2008 IP
  11. pokefreak

    pokefreak Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    why would you want to block user agents?
    Blocking opera and firefox blocks a large portion of internet users.
    If you want to block a specific user, use their IP
    Useragents are not user specific, they're the way a browser identifies itself to a website... ie all Firefox 3.0.1 browsers have the SAME useragent
     
    pokefreak, Sep 13, 2008 IP