Redirect to home if url contains string with a dot using ,htaccess

My WordPress site is under attack. A bot sends queries that crashes my MySql. All of them contains “/?s=” and “.pl” in the url, so, I whant to redirect to home if someone is trying to access them.
Example:

If www.example.com/?s=xxxxx.pl redirect to www.example.com/

Read More

If www.example.com/?s=123.pl redirect to www.example.com/

Can you help me? I couldn’t find how to edit .htaccess to solve it.

Related posts

Leave a Reply

1 comment

  1. You could use a more robust system like mod_qos to stop these types of attacks then it will automatically block them by IP and other ways.

    However you can do something like this with rewrite rule and then it will get 403 forbidden.

    RewriteEngine on
    RewriteCond %{QUERY_STRING} s=(.+).pl
    RewriteRule ^ - [F]
    

    if you still want to redirect to home page you can do this.

    RewriteEngine on
    RewriteCond %{QUERY_STRING} s=(.+).pl
    RewriteRule ^ /? [R=301,L]
    

    Let me know how this works for you.