You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by BohwaZ <ph...@bohwaz.net> on 2022/12/10 20:13:16 UTC

[users@httpd] Re:

Thank you Eric! With your help I figured it out:

SetEnvIfExpr
  "'%{DOCUMENT_ROOT}/cache/%{md5:REQUEST_URI}.html' =~ /(.+)/"
  CACHE_PATH=$0

then use it in <If> and RewriteRule, or:

RewriteCond expr "%{md5:REQUEST_URI} =~ /(.+)/"
RewriteRule .* "%{DOCUMENT_ROOT}/cache/%0.html"

Awesome :)

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


[users@httpd] Re:

Posted by BohwaZ <ph...@bohwaz.net>.
OK actually that didn't work :(

I'm doing this:

SetEnvIfExpr "%{REQUEST_URI} =~ /^(.+)(?:\?|$)/" CACHE_URI=$1
SetEnvIfExpr "md5(%{ENV:CACHE_URI}) =~ /^(.+)$/" CACHE_MD5_URI=$1

Then:
<If "-f '/home/bohwaz/cache/web/%{ENV:CACHE_MD5_URI}'">

When doing a strace I can see that Apache is doing a stat on
/home/bohwaz/cache/web/ and not on /home/bohwaz/cache/web/MD5_HASH

My understanding of the issue is that the variables defined by
SetEnvIfExpr are not available in <If> conditions.

So I resorted to using RewriteRules:

RewriteCond %{REQUEST_URI} ^(.+)(?:\?|$)
RewriteRule ^ "-" [E=CACHE_URI:%1]
RewriteCond expr "md5(%{ENV:CACHE_URI}) =~ /^(.+)$/"
RewriteRule ^ "-" [E=CACHE_URI_MD5:%1]
RewriteCond %{DOCUMENT_ROOT}/.cache/%{ENV:CACHE_URI_MD5} -f
RewriteRule ^ /.cache/%{ENV:CACHE_URI_MD5} [END]

And it works. But it would have been nice to be able to use <If> as
it's easier to read.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org