Server.on definition change when Wifi.mode is changed

You could do this once:

server.on("/", commonFunction);

And store a function pointer that would be called from commonFunction(). It would point to either handle_AP_OnConnect() or handle_OnConnect()