got the rewrite with subdomains stuff working and restructured php code