Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

ie.

Normal path:

http://www.domain.com/something/images/someimage.jpeg
http://www.domain.com/assets/js/jquery.js

.htaccess translated would turn the above into:

http://mycdn.other.com/something/images/someimage.jpeg
http://mycdn.other.com/assets/js/jquery.js

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.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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.

share|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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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