'How to pass a cookie value as a parameter with multiple rewrite conditions in htaccess

I want to first check if the request URI is an image and then check for a cookie and pass both the values as parameters to a file in the multiple rewrite conditions like below -

RewriteEngine on

RewriteCond %{REQUEST_URI} ^.*(jpeg|jpg|gif|png)$ [NC]
RewriteCond %{HTTP_COOKIE} PHPSESSID [NC]
RewriteRule ^(.*)$ index.php?q=$1&c=$2 [NC,L,R,QSA]

the above rewriterule is not passing the cookie value in the parameter. I am not good at .htaccess. Please can anyone guide me on this. Thanks in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source