Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Subsite module, DNS configuration


Go to End


20 Posts   12853 Views

Avatar
TF-35Lightning

Community Member, 137 Posts

5 May 2010 at 7:16pm

Edited: 05/05/2010 7:22pm

PS Benny in the .htaccess I have also tried subsite1.mysilverstripe, since I want to access the subsite via http://subsite1.mysilverstripe

# Subsite rewrite
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^subsite1.mysilverstripe$
RewriteRule .* sapphire/main.php?url=%{REQUEST_URI}&SubsiteID=1&%{QUERY_STRING} [L]

and Benny i presume your vhost.conf is the equivalent (the file I should be trying to replicate on my WAMP machine) of my WAMP httpd-vhosts.conf files??? I'm not 100% sure.

Avatar
bennylope

Community Member, 12 Posts

6 May 2010 at 4:09am

I'm not sure how you should go about testing this out on a WAMP server. I was doing all of this on a server running Plesk (which manages much of Apache's configuration).

You probably need to take a look at how to set up multiple domains on a WAMP server first. http://www.google.com/search?aq=1&oq=wamp+mult&sourceid=chrome&ie=UTF-8&q=wamp+multiple+domains Once you have two working and configurable domains on your machine I think you should be able to start making the subsite specific changes.

Avatar
TF-35Lightning

Community Member, 137 Posts

7 May 2010 at 4:34pm

Benny I think that is what I have been doing as far as I know (setting up multiple domains). eg

On Wamp you edit the "hosts" file

127.0.0.1 localhost
127.0.0.1 mysilverstripe
127.0.0.1 subsite1.mysilverstripe

and then edit httpd-vhosts.conf

and add in a <VirtualHost> chunk for each domain, or use the serveralias tag also

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "f:/wamp/www/silverstripe/silverstripe-v2.4.0-rc2"
ServerName mysilverstripe
ErrorLog "logs/mysilverstripe.log"
CustomLog "logs/mysilverstripe.log" common

<directory "f:/wamp/www/silverstripe/silverstripe-v2.4.0-rc2">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</directory>

</VirtualHost>

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "f:/wamp/www/silverstripe/silverstripe-v2.4.0-rc2"
ServerName subsite1.mysilverstripe
ErrorLog "logs/mysilverstripe.log"
CustomLog "logs/mysilverstripe.log" common

<directory "f:/wamp/www/silverstripe/silverstripe-v2.4.0-rc2">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</directory>

</VirtualHost>

now when I go to

mysilverstripe or subsite1.mysilverstripe they both go to the same main home page of the silverstripe site.

Any ideas?

Avatar
bennylope

Community Member, 12 Posts

8 May 2010 at 1:07am

If both domains on your WAMP server are resolving to the same SilverStripe site, then it sounds like your set up works. You just need to correctly intercept the domain name in the .htaccess file and append the SubsiteID.

Avatar
TF-35Lightning

Community Member, 137 Posts

10 May 2010 at 1:56pm

Edited: 10/05/2010 2:10pm

bennylope because I am on the grid service I don't have access to vhost.conf and MT have just said to use the .htaccess file

So I presume your working setup will not function for me... Does that mean I am out of options for getting this thing to run correctly?
I mean I guess I could always just create a subsites.mydomain.com directory and then create a file that redirects to the subsites page eg:
http://mydomain.com/subhome?SubsiteID=1

It kind of makes it difficult for when someone makes a subsite though as I would have to go and create this redirect manually, not something I really want to be doing actually.

I have tried to contact Sam the guy that wrote the subsites module and some of the other Silverstripe developers but I haven't been able to get any assistance.

Any other ideas?

Avatar
bennylope

Community Member, 12 Posts

11 May 2010 at 5:22am

I'd try simply creating another domain, whether a subdomain on your Grid Service domain or registered without hosting, and then set the A Record for that domain to point at your primary domain. With the .htaccess file in place, this should provide the correct subsite.

This is conjectural however, and I haven't tested it out myself.

Avatar
TF-35Lightning

Community Member, 137 Posts

11 May 2010 at 6:26pm

Bennylope I have not tried what you suggested in your last post, but back trying to get my WAMP to run it, to best show you my setup I have collated an image together showing the screenshots of what my subsites setup looks like.

http://www.flickr.com/photos/42659897@N08/4597647580/sizes/l/

WillR said that getting subdomains to resolve are the bulk of peoples troubles with the module and to go through the subsite.php and debug the getSubsiteID function to find out what is going wrong.

I've done my best to try and get some information from the variables to work on what is going on and atempt to do some cross checking but I don't seem to be getting to far with it, all

#Debug::show($host); gives me is subsite1.mysilverstripe

Got any ideas on what or how I should be debugging this to work out what is going on?

/**
* Get a matching subsite for the given host, or for the current HTTP_HOST.
*
* @param $host The host to find the subsite for. If not specified, $_SERVER['HTTP_HOST']
* is used.
*
* @return int Subsite ID
*/
static function getSubsiteIDForDomain($host = null, $returnMainIfNotFound = true) {

if($host == null) $host = $_SERVER['HTTP_HOST'];

$host = str_replace('www.','',$host);
$SQL_host = Convert::raw2sql($host);

$matchingDomains = DataObject::get("SubsiteDomain", "'$SQL_host' LIKE replace(\"SubsiteDomain\".\"Domain\",'*','%')",
"\"IsPrimary\" DESC", "INNER JOIN \"Subsite\" ON \"Subsite\".\"ID\" = \"SubsiteDomain\".\"SubsiteID\" AND
\"Subsite\".\"IsPublic\"=1");

if($matchingDomains) {
$subsiteIDs = array_unique($matchingDomains->column('SubsiteID'));
if(sizeof($subsiteIDs) > 1) user_error("Multiple subsites match '$host'", E_USER_WARNING);
return $subsiteIDs[0];
}

// Check for a 'default' subsite
if ($default = DataObject::get_one('Subsite', "\"DefaultSite\" = 1")) {
return $default->ID;
}

// Default subsite id = 0, the main site
return 0;

Another related function

/**
* This function gets the current subsite ID from the session. It used in the backend so Ajax requests
* use the correct subsite. The frontend handles subsites differently. It calls getSubsiteIDForDomain
* directly from ModelAsController::getNestedController. Only gets Subsite instances which have their
* {@link IsPublic} flag set to TRUE.
*
* You can simulate subsite access without creating virtual hosts by appending ?SubsiteID=<ID> to the request.
*
* @todo Pass $request object from controller so we don't have to rely on $_REQUEST
*
* @param boolean $cache
* @return int ID of the current subsite instance
*/
static function currentSubsiteID() {
if(isset($_REQUEST['SubsiteID'])) $id = (int)$_REQUEST['SubsiteID'];
else $id = Session::get('SubsiteID');

if($id === NULL) {
$id = self::getSubsiteIDForDomain();
Session::set('SubsiteID', $id);
}

return (int)$id;
}

Did you try doing this at all???

Avatar
TF-35Lightning

Community Member, 137 Posts

11 May 2010 at 7:38pm

bennylope ignore my last post about getting it working on WAMP, it is now working thank the lord!

I had to have

subsite1.mysilverstripe

as the domain in the backend of the CMS subsite section if I want to access subsite1 via subsite1.mysilverstripe

now to try and figure out a solution for a grid service where I can't access the apache virtual host files...