Symfony dynamic subdomains Symfony dynamic subdomains php php

Symfony dynamic subdomains


also going to be needing yo set your domain as a wildcard domain, if not you going to need to create manually each subdomain per client.

another solution that is not so symphony dependent is using a .htaccess

    <IfModule mod_rewrite.c>   Options +FollowSymLinks   Options +Indexes   RewriteEngine On   RewriteBase /   RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]   RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).domain.com [NC]   RewriteRule (.*) $1?sub=%2&page=$1&domain=%{HTTP_HOST} [QSA,L]<IfModule>

that code basically will send to the requested page the subdomain, the domain and the page requested. then in php you can check if it is equal to your client username. and allow you also to use parked domains for your clients at the same time.

i hope it helps.


Take a look at sfDomainRoutePlugin - it does what you want. However, in its current version you don't get the Propel or DoctrineRoute functionality, which means you must manually lookup the customer based on the subdomain parameter returned from the plugin. Example:

app/frontend/config/routing.yml

# pick up the homepagehomepage:  url:          /  class:        sfDomainRoute  param:        { module: homepage, action: index }  requirements:    sf_host:    [www.example.com, example.com]# catch subdomains for customerscustomer_subdomain:  url:          /  class:        sfDomainRoute  param:        { module: customer, action: index }

app/frontend/modules/customer/actions.class.php

public function executeIndex(sfWebRequest $request){   // get the subdomain parameter  $this->subdomain = $request->getParameter('subdomain');  // retrieve customer (you have to create the retrieveBySubdomain method)  $this->customer = CustomerPeer::retrieveBySubdomain($this->subdomain);}

This is just an example, but I use a similar approach myself, and the plugin does what is advertised. Good luck.

If you're adventurous, yuo could take a look at Chapter 2 in the "More with symfony book". This would help you understand the code in sfDomainRoutePlugin.


Because you want to load different app, filter won't help. Just use the frontcontroller (index.php) to extract the subdomain, and if the app directory exists, load the app (else 404). You can even store the id in app configuration.