Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess block requests by querystring

There is a way to block all the requests with a certain querystring?

I should block all the request that have "?userid=1234" or "&userid=1234"

For example:

/directory/page.php?userid=1234&var2=abc&var3=..
/directory/page.php?var1=test&userid=1234&var2=abc&var3=..

The directory and the page are always the same.

I know it's possibile, but i'm not sure how..

like image 884
ipel Avatar asked Dec 30 '25 13:12

ipel


1 Answers

You can check QUERY_STRING and test if it contains userid=1234.
If so, then forbid it

RewriteEngine on

RewriteCond %{QUERY_STRING} \buserid=1234\b [NC]
RewriteRule ^ - [F]

Note: \b is a word boundary anchor. Having it before and after the pattern we want to match makes sure that the rule will match exactly on userid=1234 and not on, e.g., xxxuserid=1234 or userid=1234xxx.

like image 151
Justin Iurman Avatar answered Jan 01 '26 18:01

Justin Iurman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!