Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Url rewrite in apache based on cookie value

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.

like image 571
Gnanz Avatar asked May 11 '11 10:05

Gnanz


People also ask

What is $1 in Apache rewrite rule?

$1 represents the match from the first set of parentheses in the RewriteRule regex, not in the RewriteCond regex.

What is Rewriteengine on Apache?

A rewrite engine is a component of web server software that allows you to rewrite or redirect uniform resource locators (URLs). The most popular rewrite engine is the Apache HTTP server's mod_rewrite. There are other web servers, such as nginx or lighttpd, that provide similar functions.

What is mod rewrite in Apache?

The mod_rewrite module uses a rule-based rewriting engine, based on a PCRE regular-expression parser, to rewrite requested URLs on the fly. By default, mod_rewrite maps a URL to a filesystem path. However, it can also be used to redirect one URL to another URL, or to invoke an internal proxy fetch.


1 Answers

Try this:

RewriteCond %{HTTP:Cookie} (^|;\ *)jforumUserId=([^;\ ]+)
RewriteCond %2 !=-1
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
like image 125
Gumbo Avatar answered Oct 14 '22 08:10

Gumbo