Forum Moderators: phranque
I have many websites on my server, each in a directory like
/site1/
/site2/
/site3/
inside each are lots of pages that use common scripts. these are reused classes that I employ on every site. hence I have many copies of them on my server.
/site1/library/tool1.php
/site1/library/tool2.php
/site1/library/tool3.php
/site2/library/tool1.php
/site2/library/tool2.php
/site2/library/tool3.php
/site3/library/tool1.php
/site3/library/tool2.php
/site3/library/tool3.php
typically in my PHP script, I include() them as needed, like so:
<?php include("library/tool1.php"); The obvious problem is that I'm maintaining 70+ copies of each script, one copied to each site. When I make a change to tool1.php, I have to copy that script all over the place. Human error creeps in
What I'd rather have is one /_commonscripts/ folder on my server root (e.g. sibling to "public_html" etc), which all of the sites can share:
/_commonscripts/library/tool1.php
/_commonscripts/library/tool2.php
/_commonscripts/library/tool3.php
then on my page, could I include it from a place beyond the boundaries of the current site?
<?php include("/root/myserver/_commonscripts/library/tool3.php
")?> but alas, the include() function doesn't dig deeper than the site root. The code above looks for this:
/site1/root/myserver/_commonscripts/library/tool3.php
which is actually
/root/myserver/site1/root/myserver/_commonscripts/library/tool3.php
... and that doesn't exist.
This is where the Apache part comes in
So I wondered if I could use Apache .htaccess rewriting to point local site URLs to a different one? then instead of including from the local site, it would include the file from somewhere else. brilliant!
<?php include("/_commonscripts/library/tool3.php
")?>
RewriteRule ^_commonscripts/library/(.*)$ http://www.example.com/_commonscripts/library/$1
well that didn't work.
surely there's a simple strategy for this situation
[webmasterworld.com...]
You might want to ask over in the Linux, Unix, and *nix forum if the symlinks don't work for you.
Jim