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 Link to comment https://forums.phpfreaks.com/topic/92523-need-the-right-direction/ 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 Link to comment https://forums.phpfreaks.com/topic/92523-need-the-right-direction/#findComment-474096 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? Link to comment https://forums.phpfreaks.com/topic/92523-need-the-right-direction/#findComment-474098 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? Link to comment https://forums.phpfreaks.com/topic/92523-need-the-right-direction/#findComment-474603 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. Link to comment https://forums.phpfreaks.com/topic/92523-need-the-right-direction/#findComment-474663 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.