LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-06-2016, 11:41 PM   #1
reevv
LQ Newbie
 
Registered: Aug 2016
Posts: 23

Rep: Reputation: Disabled
[apache] how to block a query string


Hello

I'm trying to block any incoming hits to this string:

[07/Aug/2016:00:56:14 +0300] "GET /?r=3
[07/Aug/2016:00:56:54 +0300] "POST /?r=3

there are other characters after 3 so i'll have to use a wildcard string.

based on a few hours of google search, i've found out that i can use an if directive, something like this:

<If "%{QUERY_STRING} =~ /?=r3*/">
Require all denied
</If>

but i think it's not written properly because if i add that to the virtualhost and restart, it crashes httpd:

AH00526: Syntax error on line 5 of /etc/apache2/sites-enabled/second.conf:
Cannot parse condition clause: Failed to compile regular expression
Action 'restart' failed.

also, i've seen that there is a way to use .htaccess with

RewriteCond %{REQUEST_URI}
RewriteRule

but i just can't understand how to write it so it uses a wildcard

if anyone can help, will be appreciated ;-)

thank you!
 
Old 08-07-2016, 01:52 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Hi,

You may try the following:
Code:
RewriteEngine on

RewriteCond %{QUERY_STRING} ^r=3
RewriteRule .* - [F]
Regards
 
Old 08-07-2016, 08:17 AM   #3
reevv
LQ Newbie
 
Registered: Aug 2016
Posts: 23

Original Poster
Rep: Reputation: Disabled
hello. thank you for your answer. i've added that to .htaccess, restarted apache and still getting hits
 
Old 08-07-2016, 08:22 AM   #4
markotitel
Member
 
Registered: Feb 2009
Location: Titel - Serbia
Posts: 181

Rep: Reputation: 18
Check carefully.

Quote:
r=3
try with

Quote:
=r3
 
Old 08-07-2016, 09:48 AM   #5
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
Originally Posted by reevv View Post
hello. thank you for your answer. i've added that to .htaccess, restarted apache and still getting hits
Are you sure that apache is indeed reading .htaccess files?
For this to happen you have to use the following inside the <Directory >..</Directory> stanza of your server DocumentRoot:
Code:
AllowOverride All
And btw there is no need to restart apache if you're editing a .htaccess file.

Regards
 
Old 08-07-2016, 12:05 PM   #6
reevv
LQ Newbie
 
Registered: Aug 2016
Posts: 23

Original Poster
Rep: Reputation: Disabled
hello and thank you for your answers!

i added bathory's method to .htaccess and checked the access.log and still got hits but didn't think to actually try to reach the /?r=3 address myself and indeed, it gives a forbidden error, which is more that i could have asked for.

thank you so much!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
htaccess block part of query string yo8rxp Linux - Server 1 01-19-2016 04:10 PM
How would you parse query string data in C? 809areacode Programming 3 09-20-2011 01:24 PM
retreive query string cpp2quser Linux - Newbie 0 03-23-2009 07:48 AM
Rewrite rule with query string in the pattern string basahkuyup Linux - Newbie 2 10-17-2006 02:06 AM
Apache redirect with query string (.htaccess) penguintutor Linux - Server 2 09-20-2006 09:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 09:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration