Forum Moderators: coopster

Message Too Old, No Replies

Can PHP create subdomains?

         

anshul

7:54 am on Apr 3, 2005 (gmt 0)

10+ Year Member



Creating somedomains; I suppose, need a update in http.conf file; curious to know, if after user registeration ( say for a blog ), subdomains can be created ( using some script ), take example:
user_lastname.user_firstname.domain_name

killroy

9:14 am on Apr 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can always use wildcards and then sort them out in the script.

SN

anshul

9:20 am on Apr 3, 2005 (gmt 0)

10+ Year Member



Couldn't get your point to the least :¦

roldar

10:23 am on Apr 3, 2005 (gmt 0)

10+ Year Member



You can create virtual subdomains using your .htaccess file. If you search in the apache forum I think you'll find several topics detailing a variety of ways you can go about it. I used this on one of my sites so that when you typed in subdomain.domain.com it appeared that way in the browser bar, when in fact it was calling a php file located at domain.com/script.php. I believe it is mod_rewrite which makes this happen. Pretty sweet but my failing memory and lost backups prevent me from giving you step-by-step instructions.

I never got very comfortable with the .htaccess file but, as I said, there are plenty of existing resources in the apache forum as well as a very capable moderator who very generously helps with these problems in the case that they haven't been answered yet.

killroy

10:42 am on Apr 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need two things. You need to set up a wildcard CNAME record on your DNS server to enable xyz.domain.com to resolve to the IP of your webserver, and u need to add ServerAlias *.domain.com in your httpd.conf file (.htaccess might work too, I don't use that though).

Now anything.domain.com will resolve to the same site as domain.com. U can then use the SERVER_NAME or similar environment variables to discover which subdomain has been called in your script. Don't forget to return proper 404 or 301 codes for the subdomains you don't use.

SN

anshul

6:28 am on Apr 5, 2005 (gmt 0)

10+ Year Member



I asked for PHP sample code or some of its built-in function ( still not sure ).
Apache file httpd.conf is inaccessible for me; what can I write in .htaccess file; if I've to write it all.

killroy

11:27 am on Apr 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I use

ServerAlias *.domain.com

try that in .htaccess

SN