9

can we write rewrite rules in apache based on the value available in cookie. below is the sample cookie value (from firebug). In this i need to control my rewrite rule based on the value jforumUserId

JSESSIONID=96A0AFA5E2EE4500C8483679DA530041;    
__utma=111872281.1699469794.1302588971.1305090522.1305099051.66; 
__utmz=111872281.1302588971.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);
 jforumUserId=1;   __utmc=111872281  

i need to force page load to https if jforumUserId value is other than -1. Is this possible.

Gnanz
  • 1,833
  • 5
  • 24
  • 51
  • Additionally, you should make sure that your cookie is secure. There is no sense in adding this redirect if the http request that precedes it also sends the cookie and is subject to cookie hijacking. – Patrick James McDougle Mar 08 '13 at 16:27

1 Answers1

18

Try this:

RewriteCond %{HTTP:Cookie} (^|;\ *)jforumUserId=([^;\ ]+)
RewriteCond %2 !=-1
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
Gumbo
  • 643,351
  • 109
  • 780
  • 844