I want to create a specialized function that check certain parameters (page requested, ip of user against a list), if the user matches he will be redirected to a different site, if he doesn’t match he will be allowed to continue to the original requested page.
However the website is cached using W3TC Page Cache, and I can’t seem to locate the place where I should put my code to act before W3TC returns the cached page.
Since W3TC serves cached pages via htaccess before PHP can do anything, you will have to either:
Do this directly in the .htaccess file before the W3TC rules.
See for example https://stackoverflow.com/questions/293285/want-to-redirect-all-visitors-except-for-me, although that won’t be possible if the list of IPs is dynamic or in a database)
Disable W3 Total Cache’s “page cache” but leave other cache types on (only if you’re not on a shared hosting plan and have a VPS or dedicated server)
Don’t panic! You’ll still get large performance improvements by leaving the “Object Cache” and the “DB Cache” on. Note that these require a memory cache module like APC or xCache installed, which, by the way, I hugely recommend).