Search code examples
apacheploneplone-4.x

Apache - Proxy external files to download


Consider this:

  • we have an external server for files that can be downloaded
  • our website (plone based) is the interface for downloading them and we try to hide the direct links as much as possible
  • jquery.fileDownload plugin needs a cookie set on file on download

I'm trying to set our Apache configuration to replace links like this:

  • original: data-files-example.com/folder/subfolder/file.zip
  • replaced: our-website-example.com/_downloads/folder/subfolder/file.zip

So, the missing part in my case is: how to set Apache to work like this?

I'm trying:

NameVirtualHost *:80
<VirtualHost :80>
    ServerAdmin [email protected]
    ServerName our-website-example.com

    RewriteEngine On
    RewriteRule "^/_downloads(.)$" "https://data-files-example.com/$1" [P] 

    RewriteCond %{REQUEST_METHOD} ^(PUT|DELETE|PROPFIND|OPTIONS|TRACE|PROPFIND|PROPPATCH|MKCOL|COPY|MOVE|LOCK|UNLOCK)$

    RewriteRule .* - [F,L]
    RewriteRule ^/(.*) http://127.0.0.1:/VirtualHostBase/http/data-files-example.com:80/my_plone_website/VirtualHostRoot/$1 [L,P]

</VirtualHost>

I receive 503 Service Unavailable.

How to fix this?


Solution

  • Following code at least rewrites your given original- to your desired target-URL:

    <VirtualHost>
        SSLProxyEngine On
        RewriteEngine On
    
        RewriteCond %{HTTP_HOST} ^our-website-example.com$
        RewriteRule   "^/_downloads(.*)$"  "https://data-files-example.com/$1"  [P,L]
    </VirtualHost>
    

    This requires the modules mod_ssl, mod_proxy and mod_rewrite to be activated.

    Let us know if it was your sought solution and if not, where it went wrong :)