Making Silverstripe play nicely with subdomains
I’ve been trying half-heartedly to get our SilverStripe installation to play nicely with our blog.gravitycomputing.co.nz subdomain for some time now. It wasn’t particularly urgent, so I left it as www.gravitycomputing.co.nz/blog, but I do prefer the ‘subdomain style’ over the ‘subfolder style’.
Anyway, I’ve recently joined the organising committee for the Innes 48-hour Challenge, which is similar to the 48hr Game Making Challenge, and the Global Service Jam. Planning is still in early stages, so I don’t particularly have any details yet, but we needed a Wiki, and so I put my hand up to host it on our website here.
This immediately brought the issue to the fore because, although it would have been nice to have my blog on a subdomain, it was basically non-negotiable for the 48-hour Challenge.
So, a quick word on our web setup here:
1) I don’t have a VPS; we use normal “shared” hosting, so I don’t have root or SSH access etc.
2) Our webhost uses cPanel, plus they have their own DNS management tool for their customers as well
3) We have a Silverstripe installation in our ~/public_html/ folder (which sets up its’
own .htaccess file). The standard Silverstripe .htaccess file reads:
### SILVERSTRIPE START ###
<Files *.ss>
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Files>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !(.gif$)|(.jpg$)|(.png$)|(.css$)|(.js$)
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]
</IfModule>
### SILVERSTRIPE END ###
4) We have our WordPress installation set up in ~/public_html/wordpress, and a MediaWiki installation set up in ~/public_html/innes48
Firstly, we set up blog.gravitycomputing.co.nz and innes48.gravitycomputing.co.nz in cPanel’s ‘subdomains’ manager. The subdomain entries point to the respective folder. Second, we set up A records in our webhost’s management tool for blog. & innes48., and pointed these to the IP address of our web server. However that wasn’t enough; any access to the subdomains would result in an error: “500 Internal Server Error”. It was there no matter what I tried. It was maddening.
However, the solution resides in a few short characters. Sixteen, it turns out, if you exclude the space. If your situation is the same as mine, all you have to do is create a new .htaccess file in the root folder of the subdomain that contains the following line:
RewriteEngine Off
That fixed it completely! The .htaccess file from the ~/public_html/ folder was interfering with access to files within the ~/public_html/innes48 folder! Yammo!
I still wanted to turn off Ugly URLs in MediaWiki, so once I learned that the .htaccess file was the culprit, I simply added one to the innes48 folder that read:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
That sorted out the access problem, and also gave me the attractive URLs that we all know from Wikipedia.
Thanks go to the answer here: http://www.silverstripe.org/general-questions/show/12225#post283492