在多个子域中维护同一项目 [英] Maintain the same project within multiple sub-domains

查看:98
本文介绍了在多个子域中维护同一项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正面临一种情况,我想对最佳方法有一些反馈/指导。

I'm facing a situation and I'd like to have some feedback/guidance about the best approach.

我有一个使用PHP和CodeIgniter开发的大型项目作为SaaS解决方案工作了一年多,并且运行良好。大约两个月前,一个新客户问我是否可以使用我的软件,但有专门为他开发的一些新功能。我说可以,并创建了一个子域,该子域包含了我的主要项目的基本结构以及他要求的新开发成果。

I have a big project developed with PHP and CodeIgniter working as a SaaS solution for more than a year and it's working perfectly. A new client about two months ago asked me if he can use my software but with some new features developed specifically for him. I said yes and created a sub-domain with the base structure of my main project along with the new developments he asked for.

现在发生了什么事,其他客户问我同样,只要我在主项目中发现错误,就必须同时进入两个子域项目并进行修复。如果错误涉及多个文件,这将花费我太多时间,并且可能会导致一些错误。

What happens is that now other client asked me the same and whenever I find a bug within the main project I have to go to both sub-domains projects and fix. If the bug involves several files..this is taking me too much time and it may create some errors.

所以,我要问的是,还有什么更好的方法吗?比为特定客户创建子域时从主项目中复制所有文件的解决方案好?

So, what I'm asking here is if there's any better solution than copy-all-files from main project when creating a sub-domain for a specific client?

我考虑过这一点:


  1. 仅在子域中使用主项目的正确文件结构创建新文件/具有新功能的固定文件。

  2. 可以通过.htaccess以某种方式重定向到子域中的文件(如果存在)吗?

这可能吗?如果是这样,怎么办?

Is this possible? If so, how?

推荐答案

如果我正确理解您的要求,则需要1个源代码,但要在2个不同的域中输出。这是我对Codeigniter所做的事情,它依赖于htaccess的一个小功能,即您可以通过htaccess设置PHP环境变量。这很有用,因为在Codeigniter中,您可以根据变量是否存在来更改到不同视图或配置文件的路径。

If I understand you correctly you want 1 source code but output in 2 different domains. This is something I've done with Codeigniter and relies on a little feature of the htaccess in that you can set PHP environment variables from with the htaccess. This is useful because in Codeigniter you can then vary paths to different views or config files dependent on if the variable is present.

您将需要单独的视图,配置和语言包和路线,但这绝对是可能的。例如,在您的htaccess中:

You will need separate views, config, language packs and routes but this is definitely possible. For example in your htaccess:

SetEnv SITE_NAME test.co.uk

然后您需要设置不同的元素:

You will then need to set different elements:


  1. 在index.php中(每个版本可能有所不同) )切换取决于 SITE_NAME 变量的URL

  2. 在index.php中,将视图文件夹更改为特定于版本的视图

  3. 按照此处的手册使用环境设置更改配置变量: https://www.codeigniter.com/userguide3/libraries/config.html

  1. In the index.php (which can vary per version) switch the URL dependent on the SITE_NAME variable
  2. In the index.php change the view folder (to your version specific views)
  3. Change your config variables using the ENVIRONMENT settings as per the manual here: https://www.codeigniter.com/userguide3/libraries/config.html

允许您运行一组具有2个前端的代码。

This will allow you to run one set of code but with 2 front ends.

这篇关于在多个子域中维护同一项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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