How to redirect site to 403 if a certain url get variable exists or contains an unwanted value using htaccess

In my site statistics, I’m staring to get strange URLs like these:

mysite.com/?p=casino-online-spielen

mysite.com/category/page/2/?p=casino-online-spielen

I’ve tried rewrites but it has messed up my WordPress rewrites or just didn’t work. I am not that good in htaccess or apache.

Read More
<IfModule mod_alias.c>
RedirectMatch 403 ?p=(casino|pharmacy)
</IfModule>

What I need is a htaccess rule that sends the user to 403 error if the word casino is found, or better yet if ?p= is found in the URL, which is not supposed to happen. But I fear it will destroy archive pagination.

On the other hand, it should allows ?s= variables and whatever is in it.

Related posts

1 comment

  1. Essentially follow @Starkeen suggestion and use mod_rewrite eg.

    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteCond %{QUERY_STRING} p=(casino|pharmacy) 
      RewriteRule .* - [F,L]
    </IfModule>
    

    Note:

    • F = Forbidden = 403
    • L = Last = Just doooooo IT.

Comments are closed.