Solved

Nearly identical sites in Apache

Posted on 2007-04-09
15
239 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
Comment Utility
#!/bin/bash
for f in siteA/httpdocs/* ; do
  ln $f siteB/httpdocs/
done
0
 
LVL 48

Expert Comment

by:Tintin
Comment Utility
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
Comment Utility
Yes. Let's say I wanted the folders to be identical, except for one file.
0
 
LVL 27

Expert Comment

by:Nopius
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 3

Author Comment

by:sypder
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry I am doing such a bad job explaining this.
0
 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now