Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess - How to set a custom header according to an environement variable?

How to set a custom header via .htaccess according to an environement variable using If/Else directive?

#Refresh-page
<If "%{ENV:DOCUMENT} == 'loading'">
    Header set Refresh "3"
</If>

I am trying to use the syntax described in the documentation for Apache 2.4

http://httpd.apache.org/docs/2.4/mod/core.html#if

TEST 1

According to anubhava's answer

RewriteCond %{ENV:DOCUMENT} ^widget$
RewriteRule ^.* - [E=REFRESH:1]

#refresh page
Header set Refresh "3" env=REFRESH

RewriteCond %{ENV:REFRESH} ^1$
RewriteRule ^.* loading.html [L]
like image 552
RafaSashi Avatar asked Sep 12 '25 23:09

RafaSashi


1 Answers

Alter your env variable to store 0 or 1 and then you can use Header set like this:

You can use:

# set DOCUMENT=widget (remove if you are already setting this)
SetEnvIf Host ^ DOCUMENT=widget

# set isDoc=1 if DOCUMENT == widget
SetEnvIf DOCUMENT widget isDoc

# set header only if isDoc == 1
Header set Refresh "3" env=isDoc
like image 60
anubhava Avatar answered Sep 16 '25 08:09

anubhava