Solved

Nearly identical sites in Apache

Posted on 2007-04-09
15
260 Views
Last Modified: 2010-08-05
I have two sites, which are virtually identical. I would like SiteB to be the same SiteA, except for a few specific files.

I would therefore like

siteB/httpdocs/* to be the same as siteA/httpdocs/* except when a particular file exists in siteB/httpdocs.

Does that make any sense?
0
Comment
Question by:sypder
  • 7
  • 5
  • 2
  • +1
15 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 18879195
#!/bin/bash
for f in siteA/httpdocs/* ; do
  ln $f siteB/httpdocs/
done
0
 
LVL 48

Expert Comment

by:Tintin
ID: 18879269
ozo's solution was what I was thinking along the lines of.

In your document root, do you want the files to be identical at that level, apart from one specific file?
0
 
LVL 3

Author Comment

by:sypder
ID: 18879295
Yes. Let's say I wanted the folders to be identical, except for one file.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 27

Expert Comment

by:Nopius
ID: 18879299
sypder, not clear what do you want, share common files (then I agree with ozo) or keep everything in one directory while one site will have more files that another (that's also possible with creating two <VirtualHost> with the same DocumentRoot and one of these VirtualHosts may have <Files filename></Files> that restricts access with 'Order Allow,Deny'.
0
 
LVL 3

Author Comment

by:sypder
ID: 18879711
Let's say I have site A and B

Site A has the following files:

page1.php
page2.php
page3.php
/images/image1.jpg
/images/image2.jpg
/images/image3.jpg

Now I want site B to have all these same files, as may be accomplished with a ln -s. But I want to override:
page2.php
/images/image3.jpg

Imagine "ln -s all files which are not in /siteB/httpdocs"
0
 
LVL 84

Expert Comment

by:ozo
ID: 18879791
the ln example above would fail when page2.php already exists, so that should do what you want.
It would also fail when images/ is a directory, which is not what you want.
You could modify it to link recursively, either letting it fail when the file already exists,
or just link everything and then change the siteB/ files that you want to be different.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 18879963
I don't know how many files you have in real life and how often you want to change them, but if you just link all files from Site A to Site B, then just unlink the specific files you want to change on site B and create a file for them.
0
 
LVL 3

Author Comment

by:sypder
ID: 18880171
Yeah, there are hundreds, and they are changing fairly often, so I was looking for an automated solution...

It may just not be possible.

Something like

if $file is not in SiteA get from SiteB.

Basically, I am designing a retail site and a wholesale site. They are on different domains, and only a few minor things, logos, pricing, etc, are different. But most of the PHP query functions, images, etc. are the same.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 18880792
Your last comment appears to be different from what you originally stated.

Are you now saying that SiteA and SiteB will be identical, apart from SiteB potentially having some different files and if so, copying/linking them across to siteA?
0
 
LVL 3

Author Comment

by:sypder
ID: 18885514
Yeah, that is what I am trying to get.

Basically, SiteB is the same as SiteA except for a few files which SiteB will have.

So basically.

if ($file is in $SiteB)
  use $SiteB/$file
else
  use $SiteA/$file
0
 
LVL 48

Expert Comment

by:Tintin
ID: 18885628
and in the instance where siteA has 'file1' and siteB has 'file1', which should be viewed?  The version on siteB?  If so, why have a different copy on siteA?
0
 
LVL 3

Author Comment

by:sypder
ID: 18885644
Okay:

Only siteA has a file: Both siteA and siteB serve that file
If both siteA and siteB has the file: siteA serves the siteA file, and siteB serves the siteB file
Only siteB has a file: Only siteB serves that file
0
 
LVL 3

Author Comment

by:sypder
ID: 18885647
Sorry I am doing such a bad job explaining this.
0
 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
ID: 18885831
OK, in that instance, what i'd do is use rsync both ways to copy any file that exists on one site and not the other.

eg:

On SiteA, do

rsync -av --ignore-existing httpdocs /siteB/httpdocs

and vice versa on SiteB.

Obviously, this isn't going to be as efficient on space as using symbolic links, but given the nature and number of changes between the sites, it's probably the easiest way of handling it (unless someone else has a brainwave)
0
 
LVL 3

Author Comment

by:sypder
ID: 18960512
Okay... So I have thought about it, and here is what I would like to do.

in my httpdocs I have:

images
includes
pages

I would like to us a symbolic link to the old site.

Then I will have

newimages
newincludes
newpages

I would like an htaccess to first see if the new version exists.

So if you request /images/image.gif, the htaccess delivers /newimages/image.gif if it exists, otherwise just deliver /images/image.gif

Does that make sense?
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Fine Tune your automatic Updates for Ubuntu / Debian
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question