Wednesday, August 27, 2014

Using Cookie as RewriteRule variable in Apache ReverseProxy

If have a cookie named myServerName, and want to check for its availability and use its content for building a URL

RewriteCond %{REQUEST_URI} ^/
RewriteCond %{HTTP_COOKIE} ^.*myServerName=([^;]+)
RewriteRule /(.*)$1 [P]

Re Write to get the content from AWS S3 Bucket RewriteEngine On RewriteCond %{HTTP_COOKIE} ^.*mycookie.*$ [NC] RequestHeader set Host '' RewriteRule (.*)/files/(.*)$2 [P] ProxyPassReverse /files/ #If no Cookies Found RewriteRule (.*)/files/(.*) [P] ProxyPassReverse /files/