开发者

One server, multiple domains, sharing PHP MVC

I'd like to produce regional versions of a php powered website, for example:

www.mysite-england.co.uk 
www.mysite-wales.co.uk 
www.mysite-scotland.co.uk 

I'd like to 开发者_运维知识库setup one LAMP server to serve all the domains with a single php MVC using $_SERVER['HTTP_HOST'] (or similar) as the primary content modifier. Ie

if($_SERVER['HTTP_HOST'] == 'mysite-wales.co.uk'){
   $region =    'wales';
   $database =  'db_wales';
   $styles=     array('wales.css', 'wales_banners.css')
   etc etc....    
}

How do i go about setting up the server to direct all these domains to the same MVC router on a single server?


Configure the Apache virtual host for the main site, and use the ServerAlias directive so it accepts connections for your other domains.

<VirtualHost *:80>
ServerName mysite-england.co.uk
ServerAlias *.mysite-england.co.uk *.mysite-wales.co.uk mysite-wales.co.uk *.mysite-scotland.co.uk mysite-scotland.co.uk
DocumentRoot /www/mysite
</VirtualHost>

More information:

  • http://httpd.apache.org/docs/2.0/vhosts/name-based.html
  • http://httpd.apache.org/docs/2.0/mod/core.html#serveralias


We did this a lot at my last job. All you do is in the vhost point all the domains at the same code base. The code base will not care what the difference is except where you define variables (I.E. Site Name, Region). Just add the server aliases to your vhost and run a switch at the top of your bootstrap.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜