English 中文(简体)
Multiple Sites with common files
原标题:

I have developed over 50 sites that all use the exact same files other than CSS and IMAGES, I currently duplicate the files each time I create a new site and upload different css and images.

What would be the best practice to simply this into 1 main location for all common files?

Here is my current structure for each site:

/home/ftpuser/public_html/commonfile1.php
/home/ftpuser/public_html/commonfile2.php
.....
/home/ftpuser/public_html/commonfileN.php
/home/ftpuser/public_html/commonfolder1/
/home/ftpuser/public_html/commonfolder2/
.....
/home/ftpuser/public_html/commonfolderN/
/home/ftpuser/public_html/css/
/home/ftpuser/public_html/css/mycssfiles.css
/home/ftpuser/public_html/images/
/home/ftpuser/public_html/images/myimages.jpg

How would I go about making all the common files located in 1 place for each site while still being able to have bespoke css and images.

I am using Apache, PHP, Centos

最佳回答

I would have your 50 virtual hosts all using the same DocumentRoot. That way you guarantee that all sites will be using the same common files.

To pick up different css and image directories, use the Alias directive to point to explict directories for each VirtualHost.

问题回答

The most obvious solution, assuming that all the different sites are hosted on the same server/filesystem, would be something akin to:

+- common files (outside web root)
|
+- httpdocs (web root)
   |
   +--+- website 1 specific files
   |      |
   |      +- images (etc)
   |
   +--+- website 2 specific files
          |
          +- images (etc)

With the above diagram, all you need to do is include the relevant files from the shared location, and override/overrule for the purposes of site specificity using the site-specific files (whether stored inside, or outside, of the web-root).

If your sites are all hosted across different servers then it gets a little more complicated, since any common files would have to be hosted somewhere in the web-root (accessible via http). This isn t ideal, though there s nothing stopping it working, but in terms of bandwidth usage and issues with cross-site security, it s likely to be problematic.

With Virtual Hosts, you re at something of a halfway house between the two options; so long as they can all access the same document root you re still able to use the includes (as suggested by dland elsewhere in these answers).

If these sites are all on the same server, you can just include the files in your php includes.

then you can just include them as if they were in the same directory as your current php file.

I think you can just #include the files that you need from the main folder, you will have to make it accessible from all the sites (using soft links will cause the server to think they are in each site s directory)

Using soft links will make it easier from the paths concerns, and you won t need to use paths "outside" your httpdocs directory.

If they re on the same server, you could just symbolic link the files:

ln -s /home/ftpuser/public_html/commonfile1.php /home/ftpuser/public_html/commonfile2.php

This breaks down in a shared hosting setup where different users (file owners) are involved.





相关问题
Using SimplePie with CodeIgniter and XAMPP

I am using CodeIgniter 1.7.2 with XAMPP 1.7.2 on a Windows computer. I am trying to make use of SimplePie. I followed all the instructions I could find: a copy of simplepie.inc is in my applications/...

Multiple Sites with common files

I have developed over 50 sites that all use the exact same files other than CSS and IMAGES, I currently duplicate the files each time I create a new site and upload different css and images. What ...

http server validation

I finish a litle http server, writing from scratch. I would like to be sure that my imlementation is conforme to the HTTP specifications. W3C give us tools for HTML/XML conformance, but i see nothing ...

热门标签