 <p>You could allow every subdomain in the first place and then check if the subdomain is valid. For example:</p> <pre><code>RewriteEngine on RewriteCond %{HTTP_HOST} ^[^.]+\.example\.com$ RewriteRule !^index\.php$ index.php [L] </code></pre> <p>Inside the <code>index.php</code> you can than extract the subdomain using:</p> <pre><code>if (preg_match('/^([^.]+)\.example\.com$/', $_SERVER['HTTP_HOST'], $match)) { var_dump($match[1]); } </code></pre> <p>But all this requires that your webserver accepts every subdomain name.</p>