gpt4 book ai didi

regex - 如何使用重写规则来测试 cookie 中的日期?

转载 作者:行者123 更新时间:2023-12-02 07:52:04 25 4
gpt4 key购买 nike

我发现你不能在下一个 Rewrite Cond 中使用 RewriteCond 反向引用作为模式条件...

我所看到的看起来是正确的,但蒂姆在下面的评论中是正确的......当我们超过保存在 cookie 中的过期日期时,这仍然是过去的。

关于如何实际测试值(value)而不是存在的任何想法?

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]

谢谢,

-埃里克

最佳答案

好吧,事实证明您理论上可以完成这项工作。但是,让我非常清楚地强调这一点,在任何情况下都不要这样做

相比于使用脚本,使用程序支持的RewriteMap(虽然并不总是可能的),或者在极端情况下编译修改后的mod_rewrite,我只能想象它的性能非常糟糕,并且由于在 .htaccess 文件中使用时必须针对每个请求进行准备,这将导致不负责任的大量开销。

也就是说,为了概念验证,132 行 mod_rewrite 亵渎:

RewriteEngine On

RewriteCond %{HTTP_COOKIE} niftyExpire=([^;\ ]+) [OR]
RewriteCond fail ^(fail)$
RewriteRule index.html$ /fail.html [E=niftyExpire:%1,E=RW_TSTATUS:%1]

RewriteCond %{ENV:RW_TSTATUS) !=fail
RewriteCond %{ENV:niftyExpire} ^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})\d{2}$
RewriteRule .* - [E=RW_CYEAR:%1,E=RW_CMON:%2,E=RW_CDAY:%3,E=RW_CHOUR:%4,E=RW_CMIN:%5]

# Check if current YY*YMMDDHHMM < cookie YY*YMMDDHHMM
#(applicable only for this decade..but that's good enough)
RewriteCond %{TIME_YEAR}%{ENV:RW_CYEAR} !^(\d{4})\1$
RewriteCond %{TIME_YEAR}%{ENV:RW_CYEAR} ^\d{2}(\d)\d{3}(\d)\d$
RewriteCond %1%2 ^(01|[01]2|[0-2]3|[0-3]4|[0-4]5|[0-5]6|[0-6]7|[0-7]8|[0-8]9)$
RewriteRule .* - [E=RW_TSTATUS:success]

RewriteCond %{ENV:RW_TSTATUS} !fail|success
RewriteCond %{TIME_YEAR}%{ENV:RW_CYEAR} ^\d{2}(\d)\d{3}(\d)\d$
RewriteCond %1%2 !^(\d)\1$
RewriteRule .* - [E=RW_TSTATUS:fail]

# Check if current YYY*MMDDHHMM < cookie YYY*MMDDHHMM
RewriteCond %{ENV:RW_TSTATUS} !fail|success
RewriteCond %{TIME_YEAR}%{ENV:RW_CYEAR} !^(\d{4})\1$
RewriteCond %{TIME_YEAR}%{ENV:RW_CYEAR} ^\d{3}(\d)\d{3}(\d)$
RewriteCond %1%2 ^(01|[01]2|[0-2]3|[0-3]4|[0-4]5|[0-5]6|[0-6]7|[0-7]8|[0-8]9)$
RewriteRule .* - [E=RW_TSTATUS:success]

RewriteCond %{ENV:RW_TSTATUS} !fail|success
RewriteCond %{TIME_YEAR}%{ENV:RW_CYEAR} ^\d{3}(\d)\d{3}(\d)$
RewriteCond %1%2 !^(\d)\1$
RewriteRule .* - [E=RW_TSTATUS:fail]

# Check if current YYYY*MDDHHMM < cookie YYYY*MDDHHMM
RewriteCond %{ENV:RW_TSTATUS} !fail|success
RewriteCond %{TIME_MON}%{ENV:RW_CMON} !^(\d{2})\1$
RewriteCond %{TIME_MON}%{ENV:RW_CMON} ^(\d)\d(\d)\d$
RewriteCond %1%2 ^01$
RewriteRule .* - [E=RW_TSTATUS:success]

RewriteCond %{ENV:RW_TSTATUS} !fail|success
RewriteCond %{TIME_MON}%{ENV:RW_CMON} ^(\d)\d(\d)\d$
RewriteCond %1%2 !^(\d)\1$
RewriteRule .* - [E=RW_TSTATUS:fail]

# Check if current YYYYM*DDHHMM < cookie YYYYM*DDHHMM
RewriteCond %{ENV:RW_TSTATUS} !fail|success
RewriteCond %{TIME_MON}%{ENV:RW_CMON} !^(\d{2})\1$
RewriteCond %{TIME_MON}%{ENV:RW_CMON} ^\d(\d)\d(\d)$
RewriteCond %1%2 ^(01|[01]2|[0-2]3|[0-3]4|[0-4]5|[0-5]6|[0-6]7|[0-7]8|[0-8]9)$
RewriteRule .* - [E=RW_TSTATUS:success]

RewriteCond %{ENV:RW_TSTATUS} !fail|success
RewriteCond %{TIME_MON}%{ENV:RW_CMON} ^\d(\d)\d(\d)$
RewriteCond %1%2 !^(\d)\1$
RewriteRule .* - [E=RW_TSTATUS:fail]

# Check if current YYYYMM*DHHMM < cookie YYYYMM*DHHMM
RewriteCond %{ENV:RW_TSTATUS} !fail|success
RewriteCond %{TIME_DAY}%{ENV:RW_CDAY} !^(\d{2})\1$
RewriteCond %{TIME_DAY}%{ENV:RW_CDAY} ^(\d)\d(\d)\d$
RewriteCond %1%2 ^(01|[01]2|[0-2]3)$
RewriteRule .* - [E=RW_TSTATUS:success]

RewriteCond %{ENV:RW_TSTATUS} !fail|success
RewriteCond %{TIME_DAY}%{ENV:RW_CDAY} ^(\d)\d(\d)\d$
RewriteCond %1%2 !^(\d)\1$
RewriteRule .* - [E=RW_TSTATUS:fail]

# Check if current YYYYMMD*HHMM < cookie YYYYMMD*HHMM
RewriteCond %{ENV:RW_TSTATUS} !fail|success
RewriteCond %{TIME_DAY}%{ENV:RW_CDAY} !^(\d{2})\1$
RewriteCond %{TIME_DAY}%{ENV:RW_CDAY} ^\d(\d)\d(\d)$
RewriteCond %1%2 ^(01|[01]2|[0-2]3|[0-3]4|[0-4]5|[0-5]6|[0-6]7|[0-7]8|[0-8]9)$
RewriteRule .* - [E=RW_TSTATUS:success]

RewriteCond %{ENV:RW_TSTATUS} !fail|success
RewriteCond %{TIME_DAY}%{ENV:RW_CDAY} ^(\d)\d(\d)\d$
RewriteCond %1%2 !^(\d)\1$
RewriteRule .* - [E=RW_TSTATUS:fail]

# Check if current YYYYMMDD*HMM < cookie YYYYMMDD*HMM
RewriteCond %{ENV:RW_TSTATUS} !fail|success
RewriteCond %{TIME_HOUR}%{ENV:RW_CHOUR} !^(\d{2})\1$
RewriteCond %{TIME_HOUR}%{ENV:RW_CHOUR} ^(\d)\d(\d)\d$
RewriteCond %1%2 ^(01|[01]2)$
RewriteRule .* - [E=RW_TSTATUS:success]

RewriteCond %{ENV:RW_TSTATUS} !fail|success
RewriteCond %{TIME_HOUR}%{ENV:RW_CHOUR} ^(\d)\d(\d)\d$
RewriteCond %1%2 !^(\d)\1$
RewriteRule .* - [E=RW_TSTATUS:fail]

# Check if current YYYYMMDDH*MM < cookie YYYYMMDDH*MM
RewriteCond %{ENV:RW_TSTATUS} !fail|success
RewriteCond %{TIME_HOUR}%{ENV:RW_CHOUR} !^(\d{2})\1$
RewriteCond %{TIME_HOUR}%{ENV:RW_CHOUR} ^\d(\d)\d(\d)$
RewriteCond %1%2 ^(01|[01]2|[0-2]3|[0-3]4|[0-4]5|[0-5]6|[0-6]7|[0-7]8|[0-8]9)$
RewriteRule .* - [E=RW_TSTATUS:success]

RewriteCond %{ENV:RW_TSTATUS} !fail|success
RewriteCond %{TIME_HOUR}%{ENV:RW_CHOUR} ^(\d)\d(\d)\d$
RewriteCond %1%2 !^(\d)\1$
RewriteRule .* - [E=RW_TSTATUS:fail]

# Check if current YYYYMMDDHH*M < cookie YYYYMMDDHH*M
RewriteCond %{ENV:RW_TSTATUS} !fail|success
RewriteCond %{TIME_MIN}%{ENV:RW_CMIN} !^(\d{2})\1$
RewriteCond %{TIME_MIN}%{ENV:RW_CMIN} ^(\d)\d(\d)\d$
RewriteCond %1%2 ^(01|[01]2|[0-2]3|[0-3]4|[0-4]5)$
RewriteRule .* - [E=RW_TSTATUS:success]

RewriteCond %{ENV:RW_TSTATUS} !fail|success
RewriteCond %{TIME_MIN}%{ENV:RW_CMIN} ^(\d)\d(\d)\d$
RewriteCond %1%2 !^(\d)\1$
RewriteRule .* - [E=RW_TSTATUS:fail]

# Check if current YYYYMMDDHHM* < cookie YYYYMMDDHHM*
RewriteCond %{ENV:RW_TSTATUS} !fail|success
RewriteCond %{TIME_MIN}%{ENV:RW_CMIN} !^(\d{2})\1$
RewriteCond %{TIME_MIN}%{ENV:RW_CMIN} ^\d(\d)\d(\d)$
RewriteCond %1%2 ^(01|[01]2|[0-2]3|[0-3]4|[0-4]5|[0-5]6|[0-6]7|[0-7]8|[0-8]9)$
RewriteRule .* - [E=RW_TSTATUS:success]

RewriteCond %{ENV:RW_TSTATUS} !fail|success
RewriteCond %{TIME_MIN}%{ENV:RW_CMIN} ^\d(\d)\d(\d)$
RewriteCond %1%2 !^(\d)\1$
RewriteRule .* - [E=RW_TSTATUS:fail]

RewriteCond %{ENV:RW_TSTATUS} !=fail
RewriteRule .* /pass.html

如果有人有更简单的方法,或者可以建议可以进一步简化的方法,我会洗耳恭听。我可能通过写这个怪物犯下了反人类罪,但至少我们现在可以说这不是不可能的。

关于regex - 如何使用重写规则来测试 cookie 中的日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3206824/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com