Apache RewriteRule : Set a session cookie on localhost

Here are the 2  (often left out) requirements to set a cookie using httpd’s rewrite rule (mod_rewrite), while working on localhost:

  1. Use the IP instead of localhost/machine-name as the domain; e.g. [CO=someCookie:someValue:], which says create a cookie “someCookie” with value “someValue” for the domain “” having a life time of 2 mins, for any path in the domain (path=/). (Obviously you will have to run the application with this value in the URL)
  2. To make a session cookie, limit the flag statement to just three attributes: name, value and domain. e.g [CO=someCookie:someValue:] – Any further settings, apache writes an” expires” attribute for the set-cookie header, which makes the cookie a persistent one (not really persistent, as the expires value set is the current server time – so you don’t even get to see your cookie!)
Kj [/.] Sreekumar programs computers as a hobby and profession. Into programming from his school days, Sree uses Codemarvels to key in facts and fixes he finds interesting while working on different projects. Some of the articles here give away a few shades of his philosophical leanings too.

Leave a Comment

Your email address will not be published. Required fields are marked *