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

Code:
RewriteCond %{REQUEST_URI} ^/
RewriteCond %{HTTP_COOKIE} ^.*myServerName=([^;]+)
RewriteRule /(.*) http://%1.test.com.au/$1 [P]


Re Write to get the content from AWS S3 Bucket RewriteEngine On RewriteCond %{HTTP_COOKIE} ^.*mycookie.*$ [NC] RequestHeader set Host 's3-ap-southeast-2.amazonaws.com' RewriteRule (.*)/files/(.*) http://s3-ap-southeast-2.amazonaws.com/mybucket/$2 [P] ProxyPassReverse /files/ http://s3-ap-southeast-2.amazonaws.com/mybucket/ #If no Cookies Found RewriteRule (.*)/files/(.*) http://s3-ap-southeast-2.amazonaws.com/mybucket//error_url/error.html [P] ProxyPassReverse /files/ http://s3-ap-southeast-2.amazonaws.com/mybucket/