up vote 1 down vote favorite
share [g+] share [fb]

A client is looking to prefix all my subdomains with www.

E.g.

www.subdomain.domain.com

I could do it through DNS but the problem is that the sub domains are user generated and it would be a pain to setup a new CNAME everytime a user signs up.

Is this possible to do in a .htaccess file?

Cheers

link|improve this question
1  
I think this is a severfault.com question. – ricbax Nov 27 '09 at 16:03
yeah your right, I followed a question from stackoverflow here and decided to post here, didn't realise there was another site for server related questions. – digital Nov 27 '09 at 16:29
this question will be migrated automatically if it needs migrating; please don't post the same question on serverfault (but don't sweat it if you already have). once this question migrates, you can sign in to serverfault, associate your accounts and take control of the migrated question. – quack quixote Nov 27 '09 at 19:04
feedback

migrated from superuser.com Nov 27 '09 at 22:15

This question came from our site for computer enthusiasts and power users.

1 Answer

up vote 3 down vote accepted

Setup a blanket answer in your DNS:

*.domain.com.   	IN      A       ip.address.of.server

Then in .htaccess [Or something similar]:

RewriteEngine on
RewriteCond %{http_host} .
RewriteCond %{http_host} !^www.domain.com [NC]
RewriteCond %{http_host} ^([^.]+)\.domain.com [NC]
RewriteRule ^(.*) http://www.domain.com/%1/ [R=301,L,QSA]
link|improve this answer
Thank you very much! – digital Nov 30 '09 at 10:48
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.