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.

Basically I want to create a situation where files served from my /cdn directory to use my cdn host rather than the local host.

How can I do this with apache rewrite?

I tried this but it doesnt work =/

RewriteEngine On
RewriteBase /cdn
RewriteCond %{HTTP_REFERER}      ^.*\.dev\.*$ [OR]
RewriteCond %{HTTP_REFERER}      ^.*\.qa\.*$ 
RewriteRule ^/cdn/(.*)           http://www1.mycdn.com/$1
RewriteEngine Off
share|improve this question
    
    
i didnt see anything in there that answered my question, but thanks! –  qodeninja Apr 14 '11 at 17:47
    
From the Matching Syntax part of that question RewriteRule ^/blog/(.*)$ /newblog/$1 which can be adapted to RewriteRule ^/cdn/(.*)$ http://cdn.example.com/$1 –  Chris S Apr 14 '11 at 17:50
2  
@Chris Throw an [R] on there ;). Redirection isn't much more than a footnote in the mega-answer there, so I kinda buy that argument. I'd suggest the Redirect directive; eg.: Redirect /cdn http://cdnhost/path/to/redirect –  Shane Madden Apr 14 '11 at 18:01
1  
@Shane, Doh! Thank you. @Codeninja, it's a dupe, it should be closed. Also, turning the RewriteEngine Off is going to make it not work... –  Chris S Apr 14 '11 at 18:42
show 3 more comments

1 Answer

up vote 1 down vote accepted

You've got contradictory stuff just in the code you posted. You have to leave the RewriteEngine on, you can't go turning it off at the end of the file or the server won't do aything. Also You can't set RewriteBase and then reference that folder in your matches later, so drop that rule too.

Other than that, it looks like several people have commneted with using just a Redirect instead, and one person gave you a cleaned up RewriteRule method.

share|improve this answer
add comment

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.