Forum Moderators: phranque
RewriteEngine on
RewriteCond %{HTTP_HOST}!^(www\.)?example\.com [NC]
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com [NC]
RewriteRule .* http://www.example.com/blog/%1 [R=301,L]
mod_rewrite is working for other requests on my server, but not for this. My host said the subdomain MUST be created. Without a valid subdomain it will not be able to resolve any DNS servers to resolve the webspace.
I want to get my own server with root access, would I be able to get around this?
They're right. You'll need to edit your DNS zone file to add "A records" for the subdomains (or a wild-card "*"). This is how the client (browser or search robot) gets the IP address associated with your subdomains, and accesses your server. Without these entries, it's likely that all subdomains except for "www" won't resolve in DNS, and the client then has no idea where it needs to send TCP/IP packets to. If it can't get to your server (by IP address), then your code won't run, and the client will get a DNS resolution error (with the message depending on the browser).
So, it's a contradiction, but true: In order to support "non-existent" subdomains, you have to define them in DNS.
Ref: DNS Oversimplified [rscott.org]
Jim