Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Sydney, Australia
    Thanked 932 Times in 919 Posts

    Multiple Sites - Mostly Common code

    I am going to have a number of separate sites - let's call them example1.com, example2.com, example1000.com and so on.

    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.
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  2. #2
    Regular Coder
    Join Date
    Oct 2004
    Thanked 26 Times in 26 Posts
    For static files you could use an Alias and mod_rewrite.

    server config/virtual hosts
    # Make the files available on all domains
    Alias /xyz123 /path/to/shared/files
    .htaccess (could be modified for vhost)
    # If the requested file doesn't exist in this domain's file tree
    RewriteCond %{SCRIPT_FILENAME} !-f
    # and it does exist in the shared directory
    RewriteCond /path/to/shared/$1 -f
    # Limited to certain shared  directories. Pass Through to Alias.
    RewriteRule ^((images|css|js|pdfs|etc\.)(/.+)$ /xyz123/$1 [PT,QSA,L]
    But for PHP includes() you'd need file system hardlinks.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts