Remote SSI Includes

I have been working on a project recently that includes header and footer bars much similar to Facebook style sites, but due to client requirements the site must remain accessible, which rules out using javascript for including the components.

On larger projects ESI has been great for doing remote includes, but due to no ESI support in Apache and no use of proxy/cdn servers in this project ESI was just not going to be possible. SSI of course was the next logical step, something Apache supports, but unfortunately doesn’t allow remote includes.

I thought about including a local proxy file such as a CGI or PHP file which could then issue the remote request and feed the data back, but this seemed hackish. There had to be a better way. It turns out there is.

If you have mod_proxy compiled into Apache then you are all set. Using ProxyPass we can make remote directories pretend to be local directories in Apache, and we can SSI include remote resources over a ProxyPass.

For example, should I wish to include resources from http://foo.com/includes/ I start by creating a proxy pass to my remote resources in my Apache virtualhost.

ProxyPass /remote http://foo.com/includes

I can then use local SSI includes:

 <-- #include virtual="/remote/myfile.html" -->

This is interpreted by Apache and then run through the ProxyPass resulting in an include of the remote file http://foo.com/includes/myfile.html into your local site.

This has certainly made SSI a more usable option for cross-site resource sharing. Best of all – you can do those normal SSI includes inside eZ Publish templates and it gives you even greater flexibility in your projects.


 
 
 
blog comments powered by Disqus