Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm hosting assets on S3 with this kind of URL: In my application I automatically serve versioned URL to force browser to download new files after the deployment: "/1.2.3/image.jpg"

In every deployment I would only like to overwrite older files. So I need a regexp in HAProxy to rewrite this:


into this:

The other question is: will HAProxy redirect the request (visible for user) or just do that in the 'back' so this redirection will be invisible.

Thanks in advance!

share|improve this question

Here's code to do that.

acl imagereq path_beg /image.jpg

reqrep ^Host:\ 1.2.3   Host:\ if imagereq

But I don't think that's really what you want to do.

reqrep will have haproxy change where it gets the content it serves your user.

HOWEVER: If the user has to go all the way to your server, then you've already wasted most of the benefit of a good CDN. (good CDNs are closer to your users than you are, and your users win by being able to get some of your content from them instead of going all the way back to you)

When you use reqrep, you're just having haproxy pop out to the nearest CDN node to YOU instead of getting it from the server you maintain.

Ideally what you want to do is adjust your HTML to point directly at your CDN.

Take at look at view source for sites like facebook, etc. You'll see their littered with links to URLS like is an alias for is an alias for

akamai is a well known CDN provider.

By explicitly putting your cdn content locations in your raw HTML, your user only has to grab your main HTML, and all other content will be directly loaded from a CDN (hopefully) nearer to your user than you are...

You could consider having haproxy send a redirect to the user pointing them at the CDN for the content. But as I said before, if the user has already come all the way to your front door, you're wasting a lot of the benefit of a CDN.

Good luck.

share|improve this answer

Your Answer


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.