Symfony dynamic subdomains(Symfony 动态子域)
问题描述
我正在尝试将子域与 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 动态子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Symfony 动态子域
基础教程推荐
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 在多维数组中查找最大值 2021-01-01