Symfony dynamic subdomains

前端 未结 4 1072
醉话见心
醉话见心 2020-12-29 10:12

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.

4条回答
  •  隐瞒了意图╮
    2020-12-29 11:10

    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

        
       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]
    
    

    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.

提交回复
热议问题