1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

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 :

    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

    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]

    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]

    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

    Likes Received:
    Best Answers:
    Trophy Points:
    Thank You So much :D
    thelastking, Mar 19, 2013 IP