Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony dynamic subdomains

I'm trying to match subdomains to a customer id in symfony.

i.e. i have customer1.example.com and customer2.example.com

Domains are stored in a table.

When a user goes to customer1.example.com, I would like to get the subdomain, look up the domain name in the database, once matched, it will then deploy the app config for that customer and then store the customer_Id in a global attribute so i know exactly which customer I'm dealing with througout the whole application. The virtual host will have the relevant wildcard servername.

Have you managed to achieve this, and if so, how? If not, any ideas would be a great help!

I'm thinking about using a filter to do it.

:-)

like image 990
Flukey Avatar asked Jun 07 '10 12:06

Flukey


1 Answers

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.

like image 139
shadow_of__soul Avatar answered Oct 06 '22 14:10

shadow_of__soul