Symfony Resources Central

Web development made simple

A new index.php controller for subdomains

The default behaviour of symfony, is to create one myapp.php and one myapp_dev.php public controller by application, knowing that the first application you create will have its prod controller renamed to index.php (default application). But this behaviour can be easily overriden to take advantage of subdomains.

-->

Here is a little file replacing every public controllers of symfony by an unique index.php, to select the application and environment depending on current subdomain (you can even change it to select depending of the domain though). The aim is to get your different applications on the following domain names:

  • http://blog.example.com
  • http://blog-dev.example.com
  • http://forum.example.com
  • http://forum-dev.example.com
  • http://www.example.com
  • http://www-dev.example.com

The *-dev domains are the development environment version of their matching non-dev subdomains, and thoose will only be available from authorized IPs, to avoid exposing too much information to the public. You only need to get the source given at the bottom of this article and substitute %project_dir%/web/*.php by this unique index.php, then customize it to fit your applications name and your subdomains.

Note that in this example, i have a fallback 'website' app for non existing subdomains, that pass the current subdomain to it through the SF_SUBDOMAIN constant. Using this, you could for example give a homepage to each of your users, or create a white label site for each of your clients... Possibilities are just limited by your imagination.

Related links:

 

Share it!

Del.icio.us Digg Furl Fuzz Stumble Upon Yahoo MyWeb 

Comments

1. On Monday, June 2 2008, 23:55 by Dain

Just the trick for my problem; works like a charm. THanks!

Add a comment

HTML code is displayed as text and web addresses are automatically converted.

This post's comments feed

© Copyright 2007-2008 daKrazy. All rights reserved.

Design and template by hartym