?
Solved

Auto subDomain creation..

Posted on 2006-10-30
4
Medium Priority
?
429 Views
Last Modified: 2008-03-10


i need to create subdomains dynamically via PHP in an Apache based web server.

im leaning towards XYZ.COM/NEWDOMAIN versus NEWDOMAIN.XYZ.COM

as simple as possible, maybe just the building blocks.

editing the httpd.conf and named.db are required? or can't i just create a subdirectory for the New User off the main, and call it good?


advice?

-n8

0
Comment
Question by:n8dog
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 5

Accepted Solution

by:
sebastienbo earned 1000 total points
ID: 17835539
Hi,

I always do the following:

1) forward subdomain or *.yourdomain.com wildcard to your webserver with A records
2) change your very first page (index.php) by putting a subdomain handler in it

subdomain handler is just removing the ".yourdomain.com" from the $_SERVER['HTTP_HOST'];  
the only thing left is your subdomain now you have two solutions

1) you: include($subdomain.'/'.index.php) <- with this one you have http://subdomain.yourdomain.com/
2) or you: header("Location:$subdomain/index.php") <- with this method you will fall on this url: http://yourdomain.com/subdomain

I hope this helps
0
 
LVL 7

Assisted Solution

by:CraigHarris
CraigHarris earned 1000 total points
ID: 17838206
Setup *.example.com in your DNS (as applicable for your domain)

In httpd.conf (or vhosts.conf if using Apache 2.2.x), add:

    ServerAlias *.example.com

To your virtual host definition (or server-wide if not using vhosts)

Then use mod_rewrite so that Apache will always pick correct directory - no special PHP handling needed -- it will just work :)

So enable the mod_rewrite module, then below the server alias, add:

  RewriteEngine On
  RewriteCond   %{HTTP_HOST}                 ^.+\.example\.com$
  RewriteRule   ^(.+)                        %{HTTP_HOST}$1          [C]
  RewriteRule   ^(.+)\.example\.com(.*) /path/$1/$2

Then you just create a folder for each subdomain (including www)

So you have something like:

/path/www/index.php
/path/xyz/index.php
/path/subdomain2/index.php

Where /path is the applicable document root.

Apache will always make sure the correct files get used -- just make sure you create folders as required.

This is a clean solution with minimal developer/admin overhead ... using PHP things can get very very messy and are unlikely to appear correctly to end users.

If you need further explanation just ask.
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question