Symfony动态子域名 [英] Symfony dynamic subdomains

查看:174
本文介绍了Symfony动态子域名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将子域名与symfony中的客户id相匹配。

我有customer1.example.com和customer2.example.com



域名保存在一个表格中。



当用户转到customer1.example.com时,我想要获取子域名,在数据库中查找域名,一旦匹配,就会为该客户部署应用配置,然后将customer_Id存储在全局属性中所以我知道我通过整个应用程序处理哪个客户。虚拟主机将具有相关的通配符服务器名称。



您是否设法实现了这一目标?如果是,如何实现?如果没有,任何想法将是一个很大的帮助!



我正在考虑使用过滤器来做到这一点。

: - )

解决方案

也需要将您的域名设置为通配符域名,否则您需要为每个客户端手动创建每个子域名。使用.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中,您可以检查它是否等于您的客户端用户名。并允许您同时为您的客户使用停放的域名。



我希望它有帮助。


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.

:-)

解决方案

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.

这篇关于Symfony动态子域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆