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).