My ideal setup would be to take a current clients site, upload a .htaccess with a regex inside, that would match the URI, and if it finds a certain file extension, it would use the same path, but with an altered domain.


Normal path:


.htaccess translated would turn the above into:


I googled this for hours in a row, no luck. Again, this is for actually making use of Amazon's CloudFront. S3 is already mounted to the website for backups and storing files using s3fs, but this doesn't solve the issue since it's using S3 directly, not using the CloudFront.


Tested & Working on httpd-2.2.3-31.el5.centos

Redirect Method:

RewriteEngine On
RewriteCond %{REQUEST_URI} .*jpg$|.*gif$|.*png$ [NC]
RewriteRule (.*) http://www.google.com/$1 [R]

The R will cause the page to actually redirect to the new domain, which may or may not be exactly what your looking for.

Proxy Method:

RewriteEngine On
RewriteCond %{REQUEST_URI} .*jpg$|.*gif$|.*png$ [NC]
RewriteRule (.*) http://www.google.com/$1 [P]

The P will cause a proxy (assuming you have mod_proxy installed) which will keep the content coming from your server instead of a redirect. This will cause your server to do more work, and will generate significantly more I/O bandwidth then a redirect. Proxies are expensive but they make sure everything appears under a single domain instead of accessing a remote server or CDN for content

Edit: I've updated it to use request_URI instead of request_filename, that way files inside of subdirectoires that dont exist will still proxy / redirect.

|improve this answer|||||
  • the above cond should redirect jpg, gif, and png's. – grufftech Jun 18 '10 at 2:09
  • Superb !! Perfect solutions, worked like I wanted ! Thanks ;) – Adrian A. Jun 18 '10 at 19:23

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.