a1amattyj Posted February 22, 2008 Share Posted February 22, 2008 hello, im currently coding a multi-forum hosting script. (Hosts multiple forums from one set of files but each forum has its own database) the basics of it works. i want each new forum to have its own subdomain - e.g forumanme.domain.com not domain.com/forum/forumname/index.php wildcard dns will be used, just have no idea how i can make this work. any links or examples? thanks Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 22, 2008 Share Posted February 22, 2008 You need a virtual host I think, look into the httpd.conf Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 22, 2008 Share Posted February 22, 2008 You can use mod_rewrite to redirect all requests through a single index.php. You can use the same rewrite rule to append the subdomain as a $_GET variable. RewriteRule ^http://([^.]+).domain.com/ /index.php?sub=$1 Then in index.php: if(isset($_GET['sub'])){ mysql_connect('localhost', 'user', 'pass'); mysql_select_db($_GET['sub']); include('forum.php'); }else{ include('main_site.php'); } Lacking data validation and a slew of other features, but does that help? Quote Link to comment Share on other sites More sharing options...
a1amattyj Posted February 23, 2008 Author Share Posted February 23, 2008 You can use mod_rewrite to redirect all requests through a single index.php. You can use the same rewrite rule to append the subdomain as a $_GET variable. RewriteRule ^http://([^.]+).domain.com/ /index.php?sub=$1 Then in index.php: if(isset($_GET['sub'])){ mysql_connect('localhost', 'user', 'pass'); mysql_select_db($_GET['sub']); include('forum.php'); }else{ include('main_site.php'); } Lacking data validation and a slew of other features, but does that help? Will i need to place the same kind of code in search.php admin.php etc? Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 23, 2008 Share Posted February 23, 2008 No. That's the point. You use mod_rewrite to send every page request through index.php. index.php performs the steps necessary for all of your pages, such as establishing database connections. Then index.php includes the proper file to display, such as search.php, admin.php, forums.php, etc. Quote Link to comment 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.