Subdomain Setup with Solar

So here was my situation – I wanted to have a subdomain off of my main site, but I didn’t want to have to create a whole new docroot with an entire new Solar framework application in it. Besides being “yet another install” of the same sort of thing, it would also be a pain to keep up more than one codebase that does a lot of the same things.

This got me to thinking that there had to be a way to convince Solar that it could use the same code with the subdomain without issue. Sure enough, it could – and it was actually really easy. Here’s my situation:

I wanted to have the main domain’s stuff still work ( just like it always has but I wanted the subdomain to point to one controller out of the main application (in this case, the Solar_App_Foo controller) when the subdomain was called ( Solar makes it dead simple – it’s just a change in your config file.

Since it’s PHP driven, you can do fun things like checking to see what the value of $_SERVER[‘HTTP_HOST’] is right there in the definition:

$act=($_SERVER['HTTP_HOST']=='') ? 'foo' : 'index';

That’s all there is to it – the ternary check looks for the subdomain and sets the default controller to our Solar_App_Foo instead of the Index the rest of the site calls. And, since it’s just part of the same site, all of the links and other functionality work just fine. Plus no extra code to maintain!

Hope this helps to anyone else out there trying to work with subdomains with Solar. Thanks to the crew in #solarphp on Freenode for the help!


One comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s