Tomcat – Mixed Static and dynamic content site using AWS S3 and EC2

amazon ec2amazon s3javamod-rewritetomcat

We are installing a Java web application in a EC2 running Tomcat.
The application uses a folder for users pictures (static content)-> www.example.com/PICTURES

We use mod_jk to exclude Tomcat from serving the path /PICTURES so it is Apache who serve it.

We are planning to move /PICTURES to S3 and serve them from our bucket.

In our code we use short urls,so for example, a user picture is defined as: /PICTURES/1.jpg

We want to redirect every call from www.example.com/PICTURES/* to our bucket -> example.com.s3-website-us-east-1.amazonaws.com/PICTURES

We have been searching for the best strategy but it seems the are not an unified solution.

As far I know we should use:

a) mod_rewrite: creating regex for every static content we would like to redirect to ur bucket

b) proxy: work as a proxy to S3

Is there any other solution? What are the pros and cons?

Best Answer

Camilo create or edit your .htaccess file and add the lines:

RewriteEngine On
RewriteRule ^/PROFILES/(.+) http://pictures.example.com/PROFILES/$1 [R,L]