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

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

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)