You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by SW <s...@creationfactor.net> on 2007/11/09 11:54:03 UTC

[users@httpd] Sharing resources across virtual hosts

Hi

Say you have 2 virtual hosts set up and one of them runs your main website. On the other virtual host you want to run a "branded" (ie: differently styled, using CSS) version of the main website.

Rather than copying all the content from your main web over to the branded version (since that would then mean if you want to change some text on a page you'd have to do it in two places) is there a way for the branded site to pull in the (in this case) PHP files and some of the images from the main site yet make them appear to be coming from the branded site?

Example 1: image on main website is located at http://www.mainsite.com/images/photo.jpg and you want to display it on your branded site aswell but make the SRC link look like this: http://www.brandedsite.com/images/photo.jpg 

Example 2: You have a FAQ page on the main site (http://www.mainsite.com/faq.php) and you want to have it on the branded site too (http://www.brandedsite.com/faq.php). You want to pull the FAQ page from mainsite, apply the CSS from your branded site to change the logos and colours and display it as http://www.brandedsite.com/faq.php

This is the first time I've done anything like this. I'm pretty sure you can do this sort of thing with content management systems, but we'd rather not go down that route and presumably content managements systems use some underlying features of Apache and virtual hosts to achieve this, so that's what I'd like to find out about.

Any help or pointers greatly appreciated.

Spencer

Re: [users@httpd] Sharing resources across virtual hosts

Posted by SW <s...@creationfactor.net>.
> Unless:
> 
> Alias /faqs.php /path/to/mainsite/docroot/faqs.php
> 
> is valid?

I can answer my own question now as I finally got a test server up and running on my local machine.

It appears you can indeed map to specific files, and tests are working nicely so far :)

Cheers
Spencer

Re: [users@httpd] Sharing resources across virtual hosts

Posted by SW <s...@creationfactor.net>.
> RewriteRules are good if you need complicated mappings. For something
> simple they are not needed:
> 
> <VirtualHost *:80>
> ServerName MainSite
> DocumentRoot /path/to/www
> </VirtualHost>
> 
> <VirtualHost *:80>
> ServerName BrandedSite
> DocumentRoot /path/to/www
> Alias /css /path/to/branded/css
> Alias /specialdir /path/to/specialdir
> </VirtualHost>

Just to elaborate on the scenario a bit because I can see a problem with aliases because of this:

The mainsite has say 4 pages in the document root folder:

index.php
contact.php
faqs.php
gallery.php

On the branded site I need to have separate index.php and contact.php pages but I want to pull faqs.php and gallery.php from the main site. This would cause a problem with Alias wouldn't it because:

Alias / /path/to/mainsite/docroot

would cause index.php and contact.php to be pulled from the main site too.

Unless:

Alias /faqs.php /path/to/mainsite/docroot/faqs.php

is valid?

Regards
Spencer


Re: [users@httpd] Sharing resources across virtual hosts

Posted by Joshua Slive <jo...@slive.ca>.
On Nov 9, 2007 7:39 AM, Krist van Besien <kr...@gmail.com> wrote:
> On Nov 9, 2007 11:54 AM, SW <s...@creationfactor.net> wrote:
>
> > Any help or pointers greatly appreciated.
>
> Have a look at rewriterules.
> Probably you could have both virtual hosts share the same docroot, but
> rewrite requests for the css stylesheets to the branded version on one
> of your vhosts.

RewriteRules are good if you need complicated mappings. For something
simple they are not needed:

<VirtualHost *:80>
ServerName MainSite
DocumentRoot /path/to/www
</VirtualHost>

<VirtualHost *:80>
ServerName BrandedSite
DocumentRoot /path/to/www
Alias /css /path/to/branded/css
Alias /specialdir /path/to/specialdir
</VirtualHost>

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Sharing resources across virtual hosts

Posted by SW <s...@creationfactor.net>.
> Have a look at rewriterules.
> Probably you could have both virtual hosts share the same docroot, but
> rewrite requests for the css stylesheets to the branded version on one
> of your vhosts.

To further expand on the scenario, there may be several branded webs, in addition to each one having it's own stylesheet it will also have it's own index.php and contact.php pages but will share faqs.php and gallery.php with the main site. So each branded needs it's own document root and vhost but pull in faqs.php and gallery.php and apply it's style sheet to them.

Can rewrite rules be used, like aliases, to map to resources that are not within the webroot? I don't see any examples of this on this page http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html.

Thanks
Spencer

Re: [users@httpd] Sharing resources across virtual hosts

Posted by Krist van Besien <kr...@gmail.com>.
On Nov 9, 2007 11:54 AM, SW <s...@creationfactor.net> wrote:

> Any help or pointers greatly appreciated.

Have a look at rewriterules.
Probably you could have both virtual hosts share the same docroot, but
rewrite requests for the css stylesheets to the branded version on one
of your vhosts.


Krist

-- 
krist.vanbesien@gmail.com
krist@vanbesien.org
Bremgarten b. Bern, Switzerland
--
A: It reverses the normal flow of conversation.
Q: What's wrong with top-posting?
A: Top-posting.
Q: What's the biggest scourge on plain text email discussions?

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org