After eliminating several reasons (PHP modules, memory limitations), trying to get useful information about debugging and transferring the site to another hosting, I found that the problem was caused by rewriting rules in the .htaccess file.
In this case, the rules were added by the All In One WP Security plugin. Perhaps a newer version of the plugin would fix it, but I replaced it with another security plugin a while ago.
Having removed all the rules from .htaccess and gradually re-entering them, I found that the specific block of lines in .htaccess causing the problem was:
# 5G:[QUERY STRINGS] <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{QUERY_STRING} (\"|%22).*(<|>|%3) [NC,OR] RewriteCond %{QUERY_STRING} (javascript:).*(\;) [NC,OR] RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3) [NC,OR] RewriteCond %{QUERY_STRING} (\\|\.\./|'|='$|=%27$) [NC,OR] RewriteCond %{QUERY_STRING} (\;|'|\"|%22).* (union|select|insert|drop|update|md5|benchmark|or|and|if) [NC,OR] RewriteCond %{QUERY_STRING} (base64_encode|localhost|mosconfig) [NC,OR] RewriteCond %{QUERY_STRING} (boot\.ini|echo.*kae|etc/passwd) [NC,OR] RewriteCond %{QUERY_STRING} (GLOBALS|REQUEST)(=|\[|%) [NC] RewriteRule .* - [F] </IfModule>
source share