I have tried asking for help with pieces of this problem and each time it has turned out that the solution to what I asked hasn’t helped at all with the overall problem.
Each of these sites will have the same overall structure with separate directories for images, pdfs, includes, plots, furum, gallery etc.
Most of the files in all of the sites will be common except for most files in images and pdfs and a small number of the other files.
There will be a few cases where a slightly modified version of a file will be needed for one site.
Some of the code being used for generating pdfs and graphs and for the gallery are open source scripts where I need to be able to update the script when a new version is released so updating the PHP in all the scripts is not an option (besides which there are hundreds of files that would need changing even if this were an option).
What I would like to do is to place all of the common files in one location where there is only the one copy to maintain.and have all of the sites grab the common copy of the file if a specific version doesn’t exist for that particular site.
How can I set up a separate directory (outside of public_html) that contains all of the common files using the same directory structure as all of the sites will use and then have all of the sites retrieve files from this directory or appropriate sub-directory when a corresponding file for that particular domain doesn’t exist. In most cases the common PHP will need to get at least one of the include files from the original domain.
Basically I want all of the domains to behave as if all of the files in this external directory were in the corresponding spot within that domain’s directory except where it has been overridden by a correspondingly named file already in that directory - without actually copying all of the files across.
I already have hundreds of PHP include files - most are common but sme - particularly the one containing the database config data) will need to be separate.
Anyway, how does a PHP include file work when the main page file is not in the domain directlry and so needs to be loaded from the common directory - A 404 error doesn’t load a PHP include file.
Are all the sites on the same server? If so there is no problem with including .PHP files on the same server.
It is possible but unnecessary to include files above the “public_html” folder. I think the advantage is there is an extra layer of protection. The example shown in the following post actually does this with no problems except I was unable to load image files above the “public_html” folder.
As mentioned in the above post, I do not think there is a simple solution and a GENERIC http://specific1.com should be created and thoroughly tested. Other sites could then be added and minor common changes made to cater for the slight variations.
I am still at a loss as to what to put in the .htaccess file to do the test. I currently have all of the generic and the fist specific files all jumbled together and this includes many files where I don’t want to change the source because when I upgrade to the next version it will remove the changes so the changes can’t go in the PHP.
I have thought of setting up the .htaccess to redirect all of the not found files and folders in specific to a single PHP script and have that one try to include the corresponding file from the generic folder (which would resolve the problems of where that folder is located) but I am not sure whetherthe not found address for all the files will be passed into the PHP properly so that it can locate the correct file from generic.I am also not sure what will happen when it tries to access a page from the forum or gallery folder. Hopefully that approach will have the code running from the specific rather than the generic folder and so will look for everything starting in the specific folder and sub-folders first.
I still don’t like the idea of adding ANY php code for this though - it ought to be possible to do with just a few mod rewrite commands.
Finally got over my “dumb” moment and realised that the includes don’t use HTTP and so are not redirected by the mod rewrite. The images, plots etc will go via http and so will be redirected.
I have worked out that I can correct the include problem for the main folder by including both include folders in the path in a command at the top of each PHP page (as it will need PHP to work out which specific folder to look at).
That will just leave the forum with about three or four files that need to be redirected (I can put an include in those files to redirect to the correct location) and the gallery (also with a small number of files to redirect similar to the forum). The one piece yet to be figured out is how to redirect the gallery images folder - hopefully without having to alter any further files in the Gallery 3 script.
Thanks John for continuing to point out to me that at least some change in the PHP is required to fix this. Your responses were also enough to get me thinking about the overall structure so as to realise that inverting my original idea makes for a cleaner implementation.