Don't make life so difficult for yourself. It's much easier and, above all, requires very little effort. However, this requires a WAF such as CF WAF. With CSF you don't have the same options as with a WAF. I could describe to you in detail how you can get a much better result without CSF but...