我正在尝试将子域与 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
域存储在表中.
当用户访问 customer1.example.com 时,我想获取子域,在数据库中查找域名,匹配后,它将为该客户部署应用程序配置,然后将 customer_Id 存储在一个全局属性,所以我确切地知道我在整个应用程序中与哪个客户打交道.虚拟主机将具有相关的通配符服务器名称.
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.
:-)
还需要将您的域设置为通配符域,否则您将需要为每个客户端手动创建每个子域.
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.
另一个不太依赖于 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>
该代码基本上会将子域、域和请求的页面发送到请求的页面.然后在 php 中你可以检查它是否等于你的客户端用户名.并允许您同时为您的客户使用托管域名.
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.
希望能帮到你.
这篇关于Symfony 动态子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!