0

I want to proxy from my Amazon S3 bucket like this:

This url:

http://www.mysite.com/page1

Proxy from this url:

http://mys3.bucket.com/www.mysite.com/page1

This is working with this rule

RewriteRule .* http://mys3.bucket.com/%{HTTP_HOST} [P]

However, the complication occurs when the url contains a query string.

This url:

http://www.mysite.com/page1?search=asdf

Should proxy this url:

http://mys3.bucket.com/www.mysite.com/page1?search=asdf

To work with S3, that needs to be encoded like this so that the query string is part of the key:

http://mys3.bucket.com/www.mysite.com/page1%3Fsearch%3Dasdf

Note that only the ? and = should be encoded. % in the keys for values should be left alone.

How can you do this with Apache?

Qben
  • 2,617
  • 2
  • 24
  • 36
Chad DeShon
  • 4,732
  • 6
  • 28
  • 29

1 Answers1

1

This might work, and I belive you want the B flag to encode your query string:

RewriteRule (.*) http://mys3.bucket.com/%{HTTP_HOST}/$1 [QSA,B,P]

I was not able to verify the P flag, but it works in my test with L instead of P.

Here is a bit more information about URL-encoding using mod_rewrite:
How to encode special characters using mod_rewrite & Apache?

If you encode the URL yourself you should look into the NE flag rather than B flag.

Hope it helps you forward.

Community
  • 1
  • 1
Qben
  • 2,617
  • 2
  • 24
  • 36