Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I found out that you cannot use a RewriteCond backreference as a pattern condition in the next Rewrite Cond...

UPDATE: As it turns out, mod_rewrite doesn't expand any variables in the test pattern, so I am effectively only testing for the existence of the cookie... Any ideas on how to actually test the value instead of just the existence?

RewriteCond %{HTTP_COOKIE} niftyExpire=([^;\ ]+)
RewriteRule .*index.html /fake.html [E=niftyExpire:%1,C]
RewriteCond %{TIME} <{ENV:niftyExpire}
RewriteRule .*fake.html /pass.html [R,L]
RewriteRule .*index.html /fail.html [R,L]



share|improve this question

I'd comment instead if I had the rep...

I don't think you need the backslash you have in your examples. E.g.

RewriteCond %{HTTP_COOKIE} niftyExpire\=([^; ]+) [NC]

should just be

RewriteCond %{HTTP_COOKIE} niftyExpire=([^; ]+) [NC]

There a great resource here with some examples (not specifically about dates, but including rewrite rules based on a cookie's value):

share|improve this answer
Thanks, I had found that, unfortunately it's not working for me.... right now, I have: RewriteCond %{HTTP_COOKIE} niftyExpire\=([^; ]+) [NC] RewriteCond %{TIME} < %1 [NC] RewriteRule ^.*$ /passed.html [R=302,L,NC] which is outputting this in the error log: [Thu Jul 08 17:39:30 2010] [alert] [client] /home/niftypre/public_html/.htaccess: RewriteCond: bad flag delimiters [Thu Jul 08 17:39:30 2010] [alert] [client] /home/niftypre/public_html/.htaccess: RewriteCond: bad flag delimiters – Eric Jul 8 '10 at 22:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.