How to Block a specific [Query String] Url via .htaccess

Discussion in 'Apache' started by thelastking, Mar 18, 2013.

  1. #1
    I'm very confused right now, I don't know how to block a specific QUERY STRING url via .htaccess file, well actually I want to block this type of url :


    test.php?q=RANDOMTEXT=&tl=The%20path%20ends
    
    Code (markup):
    If anyone knows how to solve this issue please let me know and thank you in advance (y)
     
    Solved! View solution.
    thelastking, Mar 18, 2013 IP
  2. #2
    thelastking,

    You can get this done using the mod_rewrite rule below which checks for the pattern in the entire request.

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{THE_REQUEST} ^.*(test.php\?q=RANDOMTEXT=&tl=The/path/ends).* [NC]
    RewriteRule ^(.*)$ - [F,L]
    </IfModule>


    If the file name part doesnt matter much, you can use the QUERY_STRING variable as given below:



    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{QUERY_STRING} ^.*(RANDOMTEXT=&tl=The/path/ends).* [NC]
    RewriteRule ^(.*)$ - [F,L]
    </IfModule>



    I referred the excellent article on blocking requests here : http://perishablepress.com/eight-ways-to-blacklist-with-apaches-mod_rewrite/

    Good Luck!
     
    Techs@BC, Mar 19, 2013 IP
  3. thelastking

    thelastking Member

    Messages:
    106
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #3
    Thank You So much :D
     
    thelastking, Mar 19, 2013 IP