2

We have a set of static pages that will augment a customer's existing site. The pages will not reside on the customer's servers for logistical reasons and because we need to maintain control of the content. The plan is for the customer to set up a mod_rewrite rule that will funnel certain types of URLs to a single server-side handler script that will grab the appropriate file from a CDN and just output its content. This illustrates the approach:

<?php echo(file_get_contents(str_replace($customer_host, $cdn_host, $_SERVER['REQUEST_URI']))); ?>

Can anyone think of pitfalls or offer up a different approach? Is there some way to circumvent a script altogether?

  • Well since they are already giving you ability to control content on their website indirectly, wouldn't it be just easier to host same content on customer's servers? – phoops Apr 22 '14 at 7:19
  • It would be easier but their IT people are resistant. – Lana_M Apr 24 '14 at 19:02
2

Your are planning on implementing a type of "reverse proxy" in PHP. There is an Apache module that does this already: mod_proxy

You might find it easier to configure mod_proxy as a reverse proxy on your client's server rather than use PHP. mod_proxy can even be activated through rewrite rules for specific pages or directories:

RewriteEngine On
RewriteRule ^/content/(.*) http://cdnhost.example.com/$1 [P]
ProxyPassReverse  /content/ http://cdnhost.example.com/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.