2

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

digital
  • 345
  • 6
  • 13

1 Answers1

3

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] 
Eddy
  • 852
  • 5
  • 8