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
bennylope

Community Member, 12 Posts

4 August 2009 at 3:46am

I have a feeling that soon after I post this question I'll figure it out, but here goes.

I'm working with the subsites module and have successfully created subsites within SilverStripe. What I've not been able to do is get the additional domain to properly point to the SilverStripe instance. For now I'm working with a separate domain name, and that domain and the top level domain has been added to the subsites module. The instructions on the subsite module documentation are very brief and high level.

Could anyone who has successfully implemented this share what they updated (which DNS settings, pointing to what, which server settings) to get their additional domains pointing to SilverStripe and running this module properly?

Avatar
Willr

Forum Moderator, 5523 Posts

6 August 2009 at 9:09pm

Usually we do this via apache virtual hosts. DNS might work but not too sure as there will be something server side which takes a user and points then to the correct site on the server. If you are running a dedicated IP that wouldn't be an issue but if you are on a shared host you might have issues. Basically what need to do is make sure all subdomains / other domains all point to the same location - SS handles everything else.

For example (via VirtualHosts)
<VirtualHost *>
DocumentRoot /Users/Will/Sites/sitename
ServerName siteone.com
</VirtualHost>

<VirtualHost *>
DocumentRoot /Users/Will/Sites/sitename
ServerName sitetwo.com
</VirtualHost>

Avatar
bennylope

Community Member, 12 Posts

31 October 2009 at 4:51am

Thanks, Will, but - I've recently come back to the topic, tried updating the vhost.conf file in another domain to point to the SilverStripe document root, and getting no joy. Having created the subsite in the subsites module and trying the domain the browser just serves up a text file copy of the main.php file. So it's picking the right document root but not serving up anything.

I have to think that there's more to this setup than just updating the document root. For reference, I'm running this on Plesk, on a Media Temple DV.

Avatar
bennylope

Community Member, 12 Posts

28 January 2010 at 11:50am

Right oh, so of course I earlier managed to solve the "just PHP source" error, I think setting open_basedir to the target directory did the trick. However, pointing the document root of the desired subdomain/domain to the SilverStripe source loads original site, not the subsite.

Is there anyone who has successfully set up a working copy of the subsites module and can point out how they got it configured?

Again, I'm sure it's painfully obvious once you've done it, but at this point the problem is not obvious to me.

Avatar
TF-35Lightning

Community Member, 137 Posts

4 May 2010 at 7:21pm

Edited: 04/05/2010 7:21pm

bennylope have you been able to access your subsites as yet? Get them up and going?

I've installed my subsite, setup a virtual host but for the life of me I simply cannot access the subsite via:

eg. http://subsite1.mysilverstripe

etc

like it says to in the docs. I really don't know what to do.

My forum thread is at:
http://www.silverstripe.org/general-questions/show/282949?showPost=283583

Any help would be great

Avatar
bennylope

Community Member, 12 Posts

5 May 2010 at 1:46am

Edited: 05/05/2010 1:57am

Yes, I did manage to get it working, although I think an easier way was intended.

First things first, add a page to your subsite. Then try and access it from your primary domain, by entering the page name and appending the subsite ID. If your primary domain is primary.com and your page should be subsite.com/my-subsite-page, then try accessing primary.com/my-subsite-page?SubsiteID=2. Make sure you enter the actual ID of the subsite, of course, 2 or otherwise. If that works then you can move one.

The first step in the access process is to direct your subsite domain to your SilverStripe instance. Willr's example for this was good, but apparently insufficient. The problem I ran into to was figuring out how SilverStripe dynamically gets the subsite ID from the URL. It should be simple enough, but I couldn't find anything resembling this kind of query in the Subsite module code.

At any rate, since I knew I could access the subsite pages, it was simple enough to force this to happen with a little mod_rewrite action in the .htaccess file. So the second step is to update your .htaccess file to check for the incoming host name and tell SilverStripe what site to request.

In the snippets below I use primary.com and secondary.com as the domain names for the main site and the subsite domain, respectively. Here's what my vhost.conf file looks like (I'm on a Media Temple DV server running Plesk).

DocumentRoot /var/www/vhosts/primary.com/httpdocs
ServerName secondary.com
 
<Directory /var/www/vhosts/primary.com/httpdocs>
        AllowOverride All
       <IfModule sapi_apache2.c>
                php_admin_flag engine on
                php_admin_flag safe_mode off
                php_admin_value open_basedir "/var/www/vhosts/primary.com/httpdocs:/tmp"
        </IfModule>
        <IfModule mod_php5.c>
                php_admin_flag engine on
                php_admin_flag safe_mode off
                php_admin_value open_basedir "/var/www/vhosts/primary.com/httpdocs:/tmp"
        </IfModule>
</Directory>

Then I added this to my .htaccess file:

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

It's almost the same rewrite as SilverStripe's primary rewrite, but it adds an additional condition for host name, and then appends a hard coded subsite ID. This of course may differ if you're adding a different Subsite. Note that in this method you must add those lines to the .htaccess file for each additional subsite.

I would LOVE to hear from one of the developers or community members that this is the wrong way of doing this and then get the full explanation of how to get this working properly, but in the meantime this works.

Avatar
TF-35Lightning

Community Member, 137 Posts

5 May 2010 at 2:30am

Thanks Benny your a godsend, your response has been the best I have had all day, I've been hanging out in the IRC chatroom all day trying to bother people to lend me their brains but no one there today has really had that much experience with subsites unfortunatley, so it's felt a bit like hitting my head against a concrete wall all day today. (it's been a long day trying to figure this out put it that way)

Ok with the same Virtual Host setup as I have shown in my post.
http://www.silverstripe.org/general-questions/show/282949?showPost=283583

my primary domain name is
"mysilversite"

the name of my subsite is called
"subsite1"

(domain is also subsite1, primary domain box under configuration is not checked)

and the name of the page I have created under subsite1 is called
"SubHomepage"

If I type the url:
http://mysilverstripe/subhomepage?SubsiteID=1

UNBELIEVABLE!!! I can now access and see the page I created!!! (Thank goodness for that!!!, why that simple example isnt in the doc I really don't understand...)

I'm on a WAMP server for my testing but will tomorrow shift it over (even if I can't get it fully running on WAMP) to a MT Gridservice server and will try your methods then.

I take it those code snippets won't work on a WAMP machine.
I'm gonna have to leave it there for this morning (at accessing the subsite via http://mysilverstripe/subhomepage?SubsiteID=1) It's almost 1am here in OZ and I've gotta hit the hay, hopefully I'll catchup with you at some stage tomorrow.

Thanks for the help its really GREATLY appreciated. Cheers

Avatar
TF-35Lightning

Community Member, 137 Posts

5 May 2010 at 5:04pm

Hi Benny ok I'm testing your methods at the moment on my WAMP machine as I would like to get it to work on this before I swap it over my MT Gridservice server, I can see that your .htaccess file is straight forward enough.
In your example secondary.com I will call that subsite1
and my ID for that subsite is 1

so I updated my .htaccess with

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

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

Now I where the Virtual Hosts are concerned and trying to replicate your example on my WAMP setup I presume that is what is stopping me, at the moment (when I try http://subsite1.mysilverstripe/ chrome just gives me a whooops I cant find page error)

Here is my WAMP httpd-vhosts.conf

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "f:/wamp/www"
ServerName localhost
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "f:/wamp/www/silverstripe/silverstripe-v2.4.0-rc2"
ServerName mysilverstripe
ServerAlias 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>

To me that looks pretty similar to your vhost.conf example. Any ideas???
(sorry I don't have a great deal of knowledge when it comes to Apache DNS editing apart from the obvious)

Go to Top