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\.yourwebsite.com
RewriteCond %{HTTP_HOST} ([^.]+)\.yourwebsite.com
RewriteRule ^(.*)$ /path_to_your_site/httpdocs/work_out.php?url=%1

This will render abcd.yourwebsite.com into yourwebsite.com/wor_out.php?url=abc
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.

Advertisements

Responses

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

    tanpa itu, dynamic subdomain gak akan bisa resolve.

    CMIIW

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

    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 abc.yourdomain.com
    def.yourdomain.com
    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 :
    http://groups.google.com/group/cake-php/browse_thread/thread/5a576a5fbc68e6a1

    😉

  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!
    BA
    http://www.scholarshisp.com

  8. It works, but not in Drupal site (www.drupal.org) 😦 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\.vision.com
    RewriteCond %{HTTP_HOST} ([^.]+)\.vision.com
    RewriteRule ^(.*)$ /public_html/index.php?url=%1


Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

Categories

%d bloggers like this: