In some very special task we needed (don’t ask me why) to use the value of the Query string to set a response cookie. Meaning we grab the query string in a format of Name=value to set a cookie in the response header.
eg. http://www.myserver.com/myimage.gif?mycookie=myvalue
sets the cookie in the client’s browser as:
Name of cookie: mycookie
Value of cookie: myvalue

We could imagine doing it this way:
Header set Set-Cookie "%{QUERY_STRING}e"

BUT This doesn’t work based on the following information extracted from the original Apache documentation:

URL Rewriting

The %{ENV:variable} form of TestString in the RewriteCond allows mod_rewrite’s rewrite engine to make decisions conditional on environment variables. Note that the variables accessible in mod_rewrite without the ENV: prefix are not actually environment variables. Rather, they are variables special to mod_rewrite which cannot be accessed from other modules.

So here is one way to do it in Apache 2.2.x
Note: you’ll need to enable the mod_rewrite and mod_headers in Apache 2.2x
a2enmod headers
a2enmod rewrite

Apache configuration:
Servername www.myserver.com
DocumentRoot /var/www/
# Set an environment variable called COOKIE1 using the Query String value
RewriteEngine On
RewriteCond %{QUERY_STRING} (.*)
RewriteRule ^/ - [env=COOKIE1:%1]
# Set the cookie in response header using the values from the variable
Header set Set-Cookie "%{COOKIE1}e"

The image(myimage.gif) would be placed in /var/www/ directory
and the request
http://www.myserver.com/myimage.gif?mycookie=myvalue
would set the cookie:
Name of cookie: mycookie
Value of cookie: myvalue

in the client’s browser.