1Up
1Up

Reputation: 1044

.htaccess - block request if containts a word (variable)

I'm getting tons of requests on my site based on an old url (get variable) structure. Its not something humans follow, so instead of redirecting it I want to block it so it uses almost 0 resources from server.

If the url contains something like thewebsite.com/?s=bla&some_variable=1 I want to block it with prejuduce!

This is what I have but it does not seem to work.

<FilesMatch "some_variable=1$">
    order allow,deny
    deny from all
</FilesMatch>

What am I doing wrong here?

Upvotes: 1

Views: 541

Answers (1)

Justin Iurman
Justin Iurman

Reputation: 19026

You could parse query string with mod_rewrite and QUERY_STRING.

You can put this code in your root htaccess

RewriteEngine On
RewriteCond %{QUERY_STRING} some_variable=1 [NC]
RewriteRule ^ - [F]

Note: don't forget to check if mod_rewrite is enabled

Upvotes: 1

Related Questions