问题
I'm facing a situation and I'd like to have some feedback/guidance about the best approach.
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?
I thought about this:
- Only create the new files / fixed files with new features in the sub-domain with the correct file structure of the main project.
- Somehow with .htaccess "redirect" to the files from subdomain if they exist?
Is this possible? If so, how?
回答1:
This is possible... But defnitive in more than one way.
One Option is to use a VCS like GIT and push changes to a master branch if it affects core modules and then merge the commit into all other special branches. But this involves still the same files in different locations on the server.
You could also think about refactoring your project and build a core module, that is used in every project and implement some kind of module system, so that the custom modules are as pluggable as possible. Then you could import the core modules from one central location and only the specific modifications for each customer are on different locations.
But the decision for one of the solutions is higly dependend on your project structure and how the custom parts of the customers are affecting the other modules and functions.
回答2:
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.
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:
- In the index.php (which can vary per version) switch the URL dependent on the
SITE_NAME
variable - In the index.php change the view folder (to your version specific views)
- Change your config variables using the ENVIRONMENT settings as per the manual here: https://www.codeigniter.com/userguide3/libraries/config.html
This will allow you to run one set of code but with 2 front ends.
来源:https://stackoverflow.com/questions/51349433/maintain-the-same-project-within-multiple-sub-domains