tags:

views:

60

answers:

2

Pardon the dummy question, but I am trying to breakdown a bunch of web pages into subdomains and bring them up using a settings.php page. The problem is that I can only find this for the settings page:

<?php

// WEBSITE Settings
// ******************************
// Domain Name (without: http://)
define('DOMAIN_NAME', 'mydomain.com');


// Website URL // MUST be: http://www.yourdomain.com
// DO NOT include any sub-folder
define('SITE_URL', 'http://'WHYNOSUB-FOLDER.mydomain.com');
?>

Any suggestions? Thanks much, joe

A: 

We don't have much to go on since this looks like an existing app you are trying to implement but I don't see why this wouldn't work on a subdomain based on what little code we have to see. Have you tried it? That's the best way to find out.

John Conde
Sorry. Here's where the settings page is used:<?php include('settings.php'); ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head> ...I tried and got an error.I did try using the sub-domain and got an error.Thanks much for the answers, though. joe
joe
A: 

You can do as you've suggested (including a settings.php that has a hard coded domain/subdomain). The only problem with that being that you need to create a settings.php for every subdomain you create.

A more dynamic way is to use Apache's mod_rewrite. You'll obviously need to be running on Apache and not IIS.

Here is an intro to mod rewrite

I think what you want to do is get the subdomain and append that to the url as a get parameter. That way the php script can retrieve the parameter to find out what subdomain was requested. Something like this...

RewriteCond %{HTTP_HOST} ^(.*)\.example\.com$
RewriteRule ^(.*)$ http://www.example.com/?subdomain=%1

The php script then just has to check the subdomain parameter to see what subdomain was requested.

andyjdavis