newb Posted July 1, 2009 Share Posted July 1, 2009 is there a function available where i can create subdomains through php? i know this can be done with cPanel + curl but my current UNIX system doesnt have cPanel. any way to do this without it? Quote Link to comment https://forums.phpfreaks.com/topic/164423-solved-create-subdomains/ Share on other sites More sharing options...
flyhoney Posted July 1, 2009 Share Posted July 1, 2009 This isn't something you do with PHP. It's an Apache configuration thing. You should google for "Apache create subdomain". Quote Link to comment https://forums.phpfreaks.com/topic/164423-solved-create-subdomains/#findComment-867310 Share on other sites More sharing options...
mattal999 Posted July 1, 2009 Share Posted July 1, 2009 I found this on another forum: What you can do is add a new wildcard subdomain. You can do this with DNS management like the tutorial I linked to below tells you to, but if you do not have access to your DNS management you can just add a new subdomain in your cpanel. To make it wildcard just add *.yourdomain.com. After doing this give the server some time to update, but if you did it right any subdomain you go to should return the same output as your root domain name (i.e. your index page). After you add *.yourdomain.com create the .htaccess file below, and then all you have to do is have php make new directories in your root folder with the dynamic subdomain you want. This code should be placed in the htaccess file in the root of your domain, i.e. domain.com/.htaccess <IfModule mod_rewrite.c> Options +FollowSymLinks Options +Indexes RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !www.domain.com$ [NC] RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).domain.com [NC] RewriteRule (.*) %2/$1 [L] </IfModule> Source Quote Link to comment https://forums.phpfreaks.com/topic/164423-solved-create-subdomains/#findComment-867314 Share on other sites More sharing options...
newb Posted July 1, 2009 Author Share Posted July 1, 2009 yeah i know but i was wondering what are the necessary files that need to be configured for this and if its possible for a php script to access it. reason is im trying to start a website in php where people register an account and they get a subdomain like http://myaccount.myspace.com/ for example Quote Link to comment https://forums.phpfreaks.com/topic/164423-solved-create-subdomains/#findComment-867315 Share on other sites More sharing options...
Daniel0 Posted July 1, 2009 Share Posted July 1, 2009 What is the problem with the wildcard domain and mod_rewrite? Quote Link to comment https://forums.phpfreaks.com/topic/164423-solved-create-subdomains/#findComment-867319 Share on other sites More sharing options...
flyhoney Posted July 1, 2009 Share Posted July 1, 2009 In that case, you don't really need to create the subdomains. Using mod_rewrite you can extract the subdomain portion of the URL and pass that as a GET parameter to your applicaiton. Try googling for "apache rewrite subdomain GET". Quote Link to comment https://forums.phpfreaks.com/topic/164423-solved-create-subdomains/#findComment-867320 Share on other sites More sharing options...
newb Posted July 1, 2009 Author Share Posted July 1, 2009 Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/164423-solved-create-subdomains/#findComment-867342 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.