0

Possible Duplicate:
Create Subdomains on the fly with .htaccess (PHP)

I'd like to have the following domains structure with .htaccess:

domain.com        REWRITES TO   Home Page (index.php)

www.domain.com    REWRITES TO   Home Page (index.php)

blog.domain.com   REWRITES TO   index.php?page=blog

*.domain.com      REWRITES TO   index.php?page=user&id=* (where * can be anything)

Is there a way to create anything like this?

Community
  • 1
  • 1
Cainã
  • 955
  • 3
  • 13
  • 20
  • Check out [this link.](http://stackoverflow.com/questions/586129/create-subdomains-on-the-fly-with-htaccess-php) It's another question like yours with a good answer. – phpisuber01 Jan 03 '13 at 12:26

1 Answers1

0

You haven't stated which hostname you want your rewrites to use so I am assuming the www subdomain

RewriteCond %{HTTP_HOST} ^([w]{3,3}[.]{1,1}){0,1}domain.com$
RewriteRule ^$ http://www.domain.com/index.php [R,L]

RewriteCond %{HTTP_HOST} ^blog.domain.com$
RewriteRule ^.*$ http://www.domain.com/index.php?page=blog [R,L]

RewriteCond %{HTTP_HOST} !^([w]{3,3}[.]{1,1}){0,1}domain.com$
RewriteCond %{HTTP_HOST} ^([0-9a-zA-Z-]*)[.]domain.com$
RewriteRule ^.*$ http://www.domain.com/index.php?page=user&id=%1 [R,L]
William Greenly
  • 3,914
  • 20
  • 18