"I am webby and I think webby" - AjiNIMC aka Aji Issac Mathew - "I thought and I wrote".

 AjiNIMC logo - Aji Issac Mathew I am Aji Issac Mathew also known as AjiNIMC at various forums. I am webby and I think webby, being a part time blogger, this blog is a documentation of my experiences and my learning.
Blog Stats (06 June 2008): There are currently 306 posts and 1100 comments (and 397,307 spam comments), contained within 17 categories.
RSS for Aji Issac Mathew's blog 
  I am into professional Web Marketing services which includes Web marketing strategies, SEO/SEM, Content Designing, Web Designing for usability, conversion improvement and various other things. There are limited availability per month. We don't take too many clients but we make sure that all our clients get their share of success. I worked on in-house sites for over 5 years, now is the time to help others with my experience. I have a great team helping me achieve this. A very creative and experienced team. Contact aji.issac (at the rate) digitalavenues.com and get your share of success.  

 Home >

Dynamic sub-domains with PHP

Jul
29

I got this email from one of the php usergroups,

“I have to create subdomains dynamically by php when an user registered in my site. Anybody who knows the script and procedure , please send me ASAP.”

I hate repeating things so better let it go live than bury inside a usergroup. Here I go with the answer.

Step 1: Make the following entry to your apache http.conf
ServerAlias *.domain.com ( do not forget to restart apache :) )
Step 2: Now remember that all the query comes to same doc root. Now you need to catch it using .htaccess and process it the way you want.

Also make sure your dns is able to process your sub-domains properly. These simple steps will make it happen.

This post was written by AjiNIMC aka Web Kotler at 6:41 pm under category PHP(




5 Comments »

  1. You will have to do a * entry at your dns level as well to resolve these subdomains. It will be quite fast as it will resolve at your end.



    AjiNIMC on June 21, 2007 - 7:43 pm @ 7:43 pm

  2. Could you give an example of a .htaccess file for step 2? It isn’t really clear what you are saying to do. Thanks.



    John on July 5, 2007 - 12:25 pm @ 12:25 pm

  3. something like


    (This is multi blogs)
    RewriteCond %{HTTP_HOST} ^([a-zA-Z0-9]{3,})\.idealwebtools.\.com
    RewriteCond %{REQUEST_URI} !/common-blogs/*
    RewriteCond %{REQUEST_URI} !/styles-for-common-blogs/*
    RewriteRule (.*) /commonblogs/$1 [L]

    Over here all the request from subdomain (with more than 3 letters) will get executed from commonblogs folder than public_html, this .htaccess should be placed at public_html (doc root) level.

    Hope it helps.



    AjiNIMC on July 5, 2007 - 12:50 pm @ 12:50 pm

  4. Hello,

    I want to know if i use abc.idealwebtools.com/test.php then above .htacess code is enought or do i have to add some extra condition to handle this request.

    For abc.idealwebtools.com/test.php
    i want it should open /commonblogs/abc[subdomainname]/test.php



    Sandeep on September 9, 2007 - 2:10 pm @ 2:10 pm

  5. For abc.idealwebtools.com/test.php
    i want it should open /commonblogs/abc[subdomainname]/test.php

    The above htaccess will not work as it was not getting it from /commonblogs/abc[subdomainname]/ .. for this you will have do add some more lines.
    RewriteRule (.*) /commonblogs/%1/$1 [L]

    I think this should work, in case if it is not working let me know I will write the code for you :). Good day



    AjiNIMC on September 10, 2007 - 6:31 am @ 6:31 am

RSS feed for comments on this post · TrackBack URI

Share your thoughts

You are visitor number