Posted by: Adwin | September 28, 2007

Dynamic subdomains using htaccess

I found this blog  about how to create dynamic subdomain using htaccess. I will try this at home later. Actually you just need to type this on your htaccess with modrewrite
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\
RewriteCond %{HTTP_HOST} ([^.]+)\
RewriteRule ^(.*)$ /path_to_your_site/httpdocs/work_out.php?url=%1

This will render into
Isnt it simple enough ?
I will try this at home and learn more about mod_rewrite.

In case you want to know more about mod_rewrite, read this cheatsheet  from Ilovejackdaniels.



  1. berarti, DNS server harus diatur untuk DNS Wildcard Record untuk domain tersebut.

    tanpa itu, dynamic subdomain gak akan bisa resolve.


  2. yap, that’s right, we need wildcard dns for that. in linux must be type in * so that it will refer to

    but i dont know how to do that in windows since wildcard is not allowed. I tried to google around, and found dnscmd by microsoft, but i have not tried it yet 😀

  3. but for testing purpose you can just type
    in windows\system32\driver\etc\hosts


  4. hmm, thanks for reply.
    where you from? Indonesian?

    Adwin, Indonesian name look-like. 😀

  5. yes i’am 🙂 [i use english so that others can read]
    nice to know you too mr rusd 🙂

  6. More information about subdomains setup :


  7. You really know your programming – cool!
    I’ve been to Indonesia – the Riau Islands. Hope to get back there someday.

    Keep up the good work with your blog. Not to over promote, but you should check out my website. Maybe you can find grants for a graduate degree in computer science.

    Good luck!

  8. It works, but not in Drupal site ( 😦 There are not loaded styles and java scripts :(:(

    Any glue?

  9. i would like to create subdomain by htaccess but
    the code as i have used is not working so help to find the solution

    Options +FollowSymlinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\
    RewriteCond %{HTTP_HOST} ([^.]+)\
    RewriteRule ^(.*)$ /public_html/index.php?url=%1

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: