Symfony 动态子域

Symfony dynamic subdomains(Symfony 动态子域)
本文介绍了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 动态子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Subtract time in PHP(在 PHP 中减去时间)
Limit execution time of an function or command PHP(限制函数或命令 PHP 的执行时间)
How to sum N number of time (HH:MM Format)?(如何求和 N 次(HH:MM 格式)?)
How to get current time in milliseconds in PHP?(如何在 PHP 中以毫秒为单位获取当前时间?)
How to check if time is between two times in PHP(如何检查时间是否在 PHP 中的两次之间)
Convert number of minutes into hours amp; minutes using PHP(将分钟数转换为小时数分钟使用 PHP)