Here are the 2 (often left out) requirements to set a cookie using httpd’s rewrite rule (mod_rewrite), while working on localhost:
- Use the IP 127.0.0.1 instead of localhost/machine-name as the domain; e.g. [CO=someCookie:someValue:127.0.0.1:2:/], which says create a cookie “someCookie” with value “someValue” for the domain “127.0.0.1” 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)
- To make a session cookie, limit the flag statement to just three attributes: name, value and domain. e.g [CO=someCookie:someValue:127.0.0.1] – 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!)

Sreekumar (KJ) has been a hobby programmer from school days. Codemarvels is his personal blog from the year 2010, where he writes about technology, philosophy, society and a bit about physics.
He now runs a conversational AI company – DheeYantra – focusing his efforts to help businesses improve operational efficiency using digital employees powered by AI.