duangongqiong6958 2015-09-23 14:06
浏览 46
已采纳

通过子域处理多个站点

I'm trying to improve my skills in PHP by creating my own CMS infrastructure, probably based on a lightweight framework like FuelPHP.
Because I think it's better to have a goal, I would like to use this opportunity to build a multi site CMS.

It would be a CMS for a game.
Basically, here the workflow:

Somebody create an account on the main site (http://www.mainsite.com), then create a site for his server (http://my-beautiful-server.mainsite.com). People from his server would then come to the subdomain and register to interact with the forum, the gallery, updating their account, etc.

Is using subdomains a correct approach ?
If I use a wildcard for my DNS, how must the vhost be configured to redirect on the correct folder based on the subdomain ? Can I not use a folder system for each site and use only one app to handle everything by just "passing" the subdomain as a variable to the app to tell it on which site I am ? Is it reliable ?

If in the future I want to propose custom domain names, is it possible with this approach ? I would only need to handle domain name registering myself and add a vhost configuration to redirect on the correct folder ?

I'm a little lost on the correct and most robust approach.

Today I have the domain name and I will take a little VPS for testing.

Thanks a lot for any help to guide me in the good direction and sorry for my broken english, I had trouble finding ressources on the Internet.

  • 写回答

1条回答 默认 最新

  • douling8087 2015-09-23 14:10
    关注

    Is using subdomains a correct approach ?

    It is a perfectly acceptable approach.

    If I use a wildcard for my DNS, how must the vhost be configured to redirect on the correct folder based on the subdomain ?

    You use a default vhost to capture all the requests for the different hostnames.

    Then you can shuffle them around using mod_rewrite or by examining the requested hostname at the application level.

    Can I not use a folder system for each site and use only one app to handle everything by just "passing" the subdomain as a variable to the app to tell it on which site I am ? Is it reliable ?

    Yes.

    The variable will already be available to your PHP via $_SERVER['HTTP_HOST'].

    If in the future I want to propose custom domain names, is it possible with this approach ?

    Yes. There is no practical difference between a domain name and a subdomain as far as a webserver is concerned.

    I would only need to handle domain name registering myself and add a vhost configuration to redirect on the correct folder ?

    You wouldn't even need a specific vhost configuration. Your default one would suffice.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?