問題描述
我正在嘗試將子域與 symfony 中的客戶 ID 匹配.
I'm trying to match subdomains to a customer id in symfony.
即我有 customer1.example.com 和 customer2.example.com
i.e. i have customer1.example.com and customer2.example.com
域存儲在表中.
當(dāng)用戶訪問 customer1.example.com 時(shí),我想獲取子域,在數(shù)據(jù)庫中查找域名,匹配后,它將為該客戶部署應(yīng)用程序配置,然后將 customer_Id 存儲在一個(gè)全局屬性,所以我確切地知道我在整個(gè)應(yīng)用程序中與哪個(gè)客戶打交道.虛擬主機(jī)將具有相關(guān)的通配符服務(wù)器名稱.
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.
您是否設(shè)法實(shí)現(xiàn)了這一目標(biāo),如果是,如何實(shí)現(xiàn)?如果沒有,任何想法都會有很大幫助!
Have you managed to achieve this, and if so, how? If not, any ideas would be a great help!
我正在考慮使用過濾器來做到這一點(diǎn).
I'm thinking about using a filter to do it.
:-)
推薦答案
還需要將您的域設(shè)置為通配符域,否則您將需要為每個(gè)客戶端手動創(chuàng)建每個(gè)子域.
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.
另一個(gè)不太依賴于 symphony 的解決方案是使用 .htaccess
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>
該代碼基本上會將子域、域和請求的頁面發(fā)送到請求的頁面.然后在 php 中你可以檢查它是否等于你的客戶端用戶名.并允許您同時(shí)為您的客戶使用托管域名.
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.
希望能幫到你.
這篇關(guān)于Symfony 動態(tài)子域的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!