ErrorDocument 404 /404.php
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mysite.com
RewriteRule (.*) www.mysite.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mysite\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\.mysite\.com(.*)$ [NC]
RewriteCond %{REQUEST_URI} !^/alldomains
RewriteRule ^(.*)$ /alldomains%{REQUEST_URI}index.php?name=%1%2 [L,QSA]